home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 December / december_2000.iso / Intercd / root / Multimedia / audio / ^NoiseTracker / NtkSourceCode / main.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-03-28  |  188.6 KB  |  7,087 lines

  1.  
  2. /* The Original && Best, NoiseTrekker Main Source Code [Part 1]*/
  3.  
  4. // Includes ----------------------------------------------------------
  5.  
  6. #include <stdio.h>
  7. #include <CON_All.h>
  8. #include <windows.h>
  9. #include <UTIL_Filters.h>
  10. #include <io.h>
  11. #include <direct.h>
  12. #include <mmsystem.h>
  13. #include "riff.cpp"
  14. #include "resource.h"
  15. #include "Ntkfunctions.h"
  16. #include "Alphatrack.cpp"
  17. #include "tb303.cpp"
  18. #include "cubicspline.cpp"
  19.  
  20. // Definitions -------------------------------------------------------
  21.  
  22. #define delay_size 22100
  23. #define MAX_COMB_FILTERS 10
  24. #define FULLYESNO 0
  25. #define MAXLOOPTYPE 1
  26. #define MAX_TRACKS 16
  27. #define MAX_FILTER 23
  28. #define PBLEN 1572864
  29.  
  30. // Global Variables --------------------------------------------------
  31.  
  32. FILE *HDSTREAM;
  33.  
  34. unsigned char freakylines=64;
  35.  
  36. static unsigned char CompressedPointerBitmap[] = {
  37. 0x78, 0x9C, 0x8D, 0xD2, 0x31, 0x12, 0x80, 0x20, 0x0C, 0x04, 0xC0, 0xEB, 0x2D, 0x6D, 0x7C, 0x2A,
  38. 0x85, 0x0F, 0xA3, 0xF0, 0x61, 0x29, 0x2C, 0x8C, 0x03, 0xC6, 0x8C, 0x1E, 0xA7, 0x19, 0xE8, 0x76,
  39. 0x80, 0xE4, 0x98, 0x00, 0xCC, 0xBE, 0x17, 0xF4, 0x32, 0xB1, 0xCA, 0x5A, 0xB4, 0x71, 0x50, 0xB7,
  40. 0x2A, 0x4C, 0x03, 0xC2, 0x38, 0xB0, 0xDD, 0x84, 0xC9, 0x80, 0x9A, 0x06, 0x84, 0x79, 0x83, 0x87,
  41. 0x09, 0x30, 0x32, 0x23, 0x10, 0x26, 0x5F, 0x01, 0x56, 0xD1, 0xC5, 0xA9, 0x6F, 0xC6, 0x27, 0x99,
  42. 0x31, 0xCD, 0x82, 0x02, 0xDA, 0xF5, 0x9F, 0xC9, 0xEB, 0xF8, 0x3E, 0x0F, 0xD1, 0xF9, 0x5E, 0x0F,
  43. 0xEB, 0x9F, 0xED, 0x00, 0x3E, 0x8F, 0x08, 0x72 };
  44.  
  45. gear303 tb303engine[2];
  46. para303 tb303[2];
  47. unsigned char track3031=0;
  48. unsigned char track3032=0;
  49. unsigned char sl3=0;
  50. int    currentCounter=0;
  51.  
  52. // SAMPLE COUNTER
  53. struct smpos
  54. {
  55.     unsigned __int32 last;
  56.     unsigned __int32 first;
  57. };
  58.  
  59. union s_access
  60. {
  61.     smpos half;
  62.     unsigned __int64 absolu;
  63. };
  64.  
  65. int clipc=0;
  66. int    delayedCounter=0;
  67. int    delayedCounter2=0;
  68. int    delayedCounter3=0;
  69. int    delayedCounter4=0;
  70. int    delayedCounter5=0;
  71. int    delayedCounter6=0;
  72.  
  73. int Lscope[128];
  74. int Rscope[128];
  75. int Cscope=0;
  76. int CONSOLE_WIDTH=800;
  77. int CONSOLE_HEIGHT=600;
  78. int CONSOLE_HEIGHT2=600;
  79. unsigned char tbEditStep=0;
  80. int fluzy=-1;
  81. char GUIMODE=0;
  82. char act303=0;
  83. float REVERBFILTER=0.3f;
  84. bool Scopish=true;
  85. bool AMIMODE=false;
  86. int delays[MAX_COMB_FILTERS]; // delays for the comb filters
  87. int counters[MAX_COMB_FILTERS];
  88. int rev_counter=0;
  89. int rev_counter2=0;
  90. char QUALITYPLAY=1;
  91. char visiblecolums=0;
  92. int rs_coef=32768;
  93. float decays[MAX_COMB_FILTERS][2];
  94. float delay_left_buffer[MAX_COMB_FILTERS][100000];
  95. float delay_right_buffer[MAX_COMB_FILTERS][100000];
  96. char num_echoes=1;
  97.     
  98. int gui_lx=0;
  99. int gui_ly=0;
  100. char gui_pushed=0;
  101. char teac=0;
  102. int liveparam=0;
  103. int livevalue=0;
  104. int sed_display_start=0;
  105. int sed_display_length=0;
  106. int sed_range_start=0;
  107. int sed_range_end=0;
  108. bool sed_range_mode=false;
  109. int csynth_slv=0;
  110. bool fld_chan=false;
  111. bool actlogo=false;
  112. bool QUALITYCHANGE=true;
  113. int VIEWLINE=7; // BOOKMARK
  114. int VIEWLINE2=-6;
  115. int YVIEW=244; 
  116. char is_editing=0;
  117. int poskeynote=0;
  118. int poskeyval;
  119. bool trkchan=true;
  120. int pos_space=0;
  121. int glide=0;            
  122. int multifactor=4;
  123. int left_value=0;
  124. int right_value=0;
  125. int clrc=0;
  126. char seditor=0;
  127. char tipoftheday[256];
  128. int ctipoftheday=0;
  129. char ped_split=0;
  130. float oldspawn[MAX_TRACKS];
  131. float roldspawn[MAX_TRACKS];
  132. char FADEMODE[MAX_TRACKS]; // 0 - Off, 1- In, 2 - Out;
  133. float FADECOEF[MAX_TRACKS];
  134.  
  135. CSynth Synthesizer[MAX_TRACKS];
  136. Cubic Resampler;
  137.  
  138. char compressor=0; // 0-->Off 1-->On
  139. int b_buff_xsize=0;
  140. int b_buff_ysize=0;
  141. int player_pos=-1;
  142. int xew=0;
  143. bool sas=false;
  144. int flagger=0;
  145. int LastX=0;
  146. int LastY=0;
  147. int shuffleswitch=0;
  148. int ltretnote=0;
  149. int ltretvalue=0;
  150. int L_MaxLevel=0;
  151. int R_MaxLevel=0;
  152. int retletter=0;
  153. int tretletter=0;
  154. int posletter=0;
  155. Screen* S;
  156. bool poslad=true;
  157. int shufflestep=0;
  158. int lt_items=0;
  159. int lt_index=0;
  160. int last_index=-1;
  161. int gco=0;
  162. int lt_curr=0;
  163. int block_start_track=-1;
  164. int block_end_track=-1;
  165. int block_start=0;
  166. int block_end=0;
  167. int lt_ykar=200;
  168. int gui_action=255;
  169. char SMPT_LIST[2048][64];
  170. bool SACTIVE[256][16];
  171. unsigned FILETYPE[2048];
  172. bool grown=false;
  173. unsigned int Currentpointer=0;
  174. unsigned __int32 res_dec=0;
  175. int ped_row=0;
  176. int ped_line=0;
  177. char appbuffer[_MAX_PATH];
  178. char CS_PAR_NAME[52][24]; // CSynth Parameters Names
  179. int ped_track=0;
  180. int gui_track=0;
  181. int xoffseted;
  182. float gr=0;
  183. float currsygnal=0;
  184. float currsygnal2=0;
  185. float synthsygnal=0;
  186.  
  187. int po_ctrl=0;
  188. char userscreen=0;
  189. int XLATENCY_TIME=50;
  190. float left_float=0;
  191. float right_float=0;
  192. float left_chorus=0;
  193. float right_chorus=0;
  194. int shuffle=0;
  195. int c_r_release=0;
  196. int c_l_release=0;
  197. short *RawSamples[128][2][16];
  198. short *Player_WL[MAX_TRACKS];
  199. short *Player_WR[MAX_TRACKS];
  200.  
  201. float allBuffer_L[5760];
  202. float allBuffer_L2[5760];
  203. float allBuffer_L3[5760];
  204. float allBuffer_L4[5760];
  205. float allBuffer_L5[5760];
  206. float allBuffer_L6[5760];
  207.  
  208. short patternLines[128];
  209. char SampleChannels[128][16];
  210. char Player_SC[MAX_TRACKS];
  211.  
  212. char SampleType[128][16];
  213. long LoopStart[128][16];
  214. long LoopEnd[128][16];
  215. unsigned int Player_LS[MAX_TRACKS];
  216. unsigned int Player_LE[MAX_TRACKS];
  217. unsigned int Player_LL[MAX_TRACKS];
  218. unsigned int Player_NS[MAX_TRACKS];
  219.  
  220. SynthParameters PARASynth[128];
  221. char LoopType[128][16];
  222. char Player_LT[MAX_TRACKS];
  223. long SampleNumSamples[128][16];
  224. char Finetune[128][16];
  225. char SampleName[128][16][64];
  226. float SampleVol[128][16];
  227. float CustomVol[128];
  228. float Player_SV[MAX_TRACKS];
  229. float FDecay[128][16];
  230. float Player_FD[MAX_TRACKS];
  231. char Basenote[128][16];
  232. char nameins[128][20];
  233. bool beatsync[128];
  234. short beatlines[128];
  235.  
  236. char Midiprg[128];
  237. bool Synthprg[128];
  238.  
  239. char Patbreak=127; // 127 when no jump or yes on patbreak<64 = line to jump.
  240.  
  241. unsigned char *RawPatterns;
  242. unsigned char *BuffTrack;
  243. unsigned char *BuffPatt;
  244. unsigned char *BuffBlock;
  245. char name[20];
  246. char artist[20];
  247. char style[20];
  248.  
  249. unsigned char pSequence[256];
  250. unsigned char cPosition=0;
  251. unsigned char sLength=1;
  252. unsigned char nPatterns=1;
  253.  
  254. int ped_pattad=1;
  255. int ped_patoct=4;
  256. int ped_patsam=1;
  257. int ped_synthpar=1;
  258. unsigned int Rns[MAX_TRACKS];
  259. char FLANGER_ON[MAX_TRACKS];
  260. float FLANGER_AMOUNT[MAX_TRACKS];
  261. float FLANGER_DEPHASE[MAX_TRACKS];
  262. float FLANGER_RATE[MAX_TRACKS];
  263. float FLANGER_AMPL[MAX_TRACKS];
  264. float FLANGER_GR[MAX_TRACKS];
  265. float FLANGER_FEEDBACK[MAX_TRACKS];
  266. int FLANGER_DELAY[MAX_TRACKS];
  267. int FLANGER_OFFSET[MAX_TRACKS];
  268. float foff2[MAX_TRACKS];
  269. float foff1[MAX_TRACKS];
  270. float FLANGE_LEFTBUFFER[MAX_TRACKS][16400];
  271. float FLANGE_RIGHTBUFFER[MAX_TRACKS][16400];
  272. int LastProgram[MAX_TRACKS];
  273. char sp_channelsample[MAX_TRACKS];
  274. char sp_split[MAX_TRACKS];
  275. int TRACKSTATE[MAX_TRACKS]; // 0->Normal 1->Muted
  276. s_access sp_Position[MAX_TRACKS];
  277. float sp_Cvol[MAX_TRACKS];
  278. float sp_Tvol[MAX_TRACKS];
  279. int sp_Stage[MAX_TRACKS];
  280. char LFO_ON[MAX_TRACKS];
  281. float LFORATE[MAX_TRACKS];
  282. float LFOAMPL[MAX_TRACKS];
  283. float LFOGR[MAX_TRACKS];
  284. int restx=0;
  285. int resty=0;
  286. int fsize=0;
  287. bool draw_sampled_wave=false;
  288. bool draw_sampled_wave2=false;
  289. bool draw_sampled_wave3=false;
  290.  
  291. signed __int64 sp_Step[MAX_TRACKS];
  292. signed __int64 Vstep1[MAX_TRACKS];
  293. signed __int64 glidestep[MAX_TRACKS];
  294. float ramper[MAX_TRACKS];
  295. float fx1[MAX_TRACKS];
  296. float fx2[MAX_TRACKS];
  297. float fy1[MAX_TRACKS];
  298. float fy2[MAX_TRACKS];
  299. float xi0[MAX_TRACKS];
  300. float xi1[MAX_TRACKS];
  301. float xi2[MAX_TRACKS];
  302. float rx1,rx2,ry1,ry2;
  303. float rx12,rx22,ry12,ry22;
  304. int CSend[MAX_TRACKS];
  305. float CCoef[MAX_TRACKS];
  306. float coef[5];
  307. float coeftab[5][128][128][4];
  308. float buf0[MAX_TRACKS],buf1[MAX_TRACKS];
  309. float buf024[MAX_TRACKS],buf124[MAX_TRACKS];
  310. int redraw_everything=0;
  311. int pl_note=0;
  312. int pl_sample=0;    
  313. int pl_vol_row=0;
  314. int pl_pan_row=0;
  315. bool boing=false;
  316. int pl_eff_row=0;
  317. int pl_dat_row=0;
  318. int LastPedRow=-1;
  319. int Subicounter=0;
  320. bool rawrender=false;
  321. bool po_ctrl2=true;
  322. int TRACKMIDICHANNEL[MAX_TRACKS];
  323. float CCut[MAX_TRACKS];
  324. float TCut[MAX_TRACKS];
  325. float ICut[MAX_TRACKS];
  326. float TPan[MAX_TRACKS];
  327. float LVol[MAX_TRACKS];
  328. float RVol[MAX_TRACKS];
  329.  
  330. int FType[MAX_TRACKS];
  331. int FRez[MAX_TRACKS];
  332. float DThreshold[MAX_TRACKS];
  333. float DClamp[MAX_TRACKS];
  334. bool Disclap[MAX_TRACKS];
  335. bool Dispan[MAX_TRACKS];
  336. float DSend[MAX_TRACKS];    
  337. int sp_TickCounter=0;
  338. int LVColor=0;
  339. int RVColor=0;
  340. int BeatsPerMin=125;
  341. int TicksPerBeat=4;
  342. char Songtracks=8;
  343. int SamplesPerSec=44100;
  344. unsigned int SamplesPerSub=0;
  345. unsigned int SubCounter=0;
  346. unsigned int PosInTick=0;
  347. int Songplaying=0;
  348. int DelayType=0;
  349. int player_line=0;
  350. char actuloop=0;
  351. int namesize=8;
  352. int plx=0;
  353. float delay_left_final=0;
  354. float delay_right_final=0;
  355. float Feedback=0.6f;
  356. float Feedback2=0.5f;
  357. float Feedback3=0.45f;
  358. float Feedback4=0.4f;
  359. float Feedback5=0.53f;
  360. float Feedback6=0.46f;
  361.  
  362. int delay_time=0;
  363. float mas_vol=1.0f;
  364.  
  365. float lbuff_chorus[131072];
  366. float rbuff_chorus[131072];
  367. float lchorus_feedback=0.6f;
  368. float rchorus_feedback=0.5f;
  369. int lchorus_delay=10584;
  370. int rchorus_delay=15876;
  371. int c_l_tvol=32768;
  372. int c_r_tvol=32768;
  373. int c_l_cvol=32768;
  374. int c_r_cvol=32768;
  375. int c_threshold=32;
  376. int mlimit=0;
  377. long axswave=0;
  378. unsigned int lchorus_counter=44100;
  379. unsigned int rchorus_counter=44100;
  380. unsigned int lchorus_counter2=44100-lchorus_delay;
  381. unsigned int rchorus_counter2=44100-rchorus_delay;
  382.  
  383. int hd_isrecording=0;
  384. char sr_isrecording=0;
  385.  
  386. int po_shift=0;
  387. int snamesel=0;
  388.  
  389. signed char n_midioutdevices=0;
  390. signed char n_midiindevices=0;
  391. MIDIINCAPS caps_midiin[255];
  392. MIDIOUTCAPS caps_midiout[255];
  393. HMIDIOUT midiout_handle=NULL;
  394. HMIDIIN midiin_handle=NULL;
  395. Bitmap* MOUSEBACK;
  396. Bitmap* NTKLOGO;
  397. Bitmap* SKIN303;
  398. Bitmap* KNOB1;
  399. Bitmap* PFONT;
  400. Bitmap* FRAMEWORK;
  401.  
  402. HDC dc;
  403. HFONT fnt;
  404. HFONT old_f;
  405. MEMORYSTATUS memstate;
  406.  
  407. rFilter LFP_L;
  408. rFilter LFP_R;
  409.  
  410. bool midiin_changed=false;
  411. bool midiout_changed=false;
  412.  
  413. signed char c_midiin=-1;
  414. signed char c_midiout=-1;
  415. /*
  416. ok, make sure your exit function is something like:
  417.  
  418. int postAction(Console* C);
  419.  
  420. and don't call it directly.  instead add:
  421.   setPostAction(postAction);
  422.  
  423. to the initConsole
  424.  
  425. This will attach the function to the library exit code, and will be executed automatically
  426. */
  427. // Initializing Console -----------------------------------------
  428.  
  429. int initConsole(int& Width, int& Height, int& FullScreen, int& Flags, Screen* S)
  430. {
  431. LoadSettings();                /* Load configuration file */
  432. restx=CONSOLE_WIDTH-640;
  433. resty=CONSOLE_HEIGHT-480;
  434. CONSOLE_HEIGHT2=CONSOLE_HEIGHT-22;
  435. mlimit=619+restx;
  436. fsize=638+restx;
  437. visiblecolums=CONSOLE_WIDTH/128;
  438. ctipoftheday=rand() % 15;    
  439. switch(ctipoftheday){
  440. case 0:sprintf(tipoftheday,"Tip Of The Day: Pressing CTRL+I will interpolate effect value on the marked block.");break;
  441. case 1:sprintf(tipoftheday,"Tip Of The Day: The right mouse button will have a secondary action on most buttons.");break;
  442. case 2:sprintf(tipoftheday,"Tip Of The Day: Dont set excesive track reverb send values, to get better quality.");break;
  443. case 3:sprintf(tipoftheday,"Tip Of The Day: Use CTRL+Z to paste only effect data of the marked block.");break;
  444. case 4:sprintf(tipoftheday,"Remember: MIDI is not audio, realtime fx will no affect to midi sound.");break;
  445. case 5:sprintf(tipoftheday,"'ArGuru': I hate Cubase...");break;
  446. case 6:sprintf(tipoftheday,"Tip Of The Day: Get very-latest 'NoiseTrekker' versions at 'http://agarrense.freeservers.com'.");break;
  447. case 7:sprintf(tipoftheday,"Tip Of The Day: On lower CPUs, you can renderize patterns to wav, and use them as samples without any loss of quality.");break;
  448. case 8:sprintf(tipoftheday,"Tip Of The Day: Volume note-cut command 'F?' is very useful to avoid sample-clicking.");break;
  449. case 9:sprintf(tipoftheday,"Tip Of The Day: Left-Clicking on pattern editor will mute/unmute any track.");break;
  450. case 10:sprintf(tipoftheday,"Tip Of The Day: Pattern command '16xx' will reset the Filter LFO of the track. No parameter required.");break;
  451. case 11:sprintf(tipoftheday,"Tip Of The Day: With a '90' value on the panning column you can change midi controllers values.");break;
  452. case 12:sprintf(tipoftheday,"Tip Of The Day: Get lastest music-software stuff at www.maz-sound.de.");break;
  453. case 13:sprintf(tipoftheday,"Tip Of The Day: Official 'NoiseTrekker' site by Waka-X at http://twnn.cjb.net.");break;
  454. case 14:sprintf(tipoftheday,"Tip Of The Day: Pressing Left-Shift will 'key-repeating' while editing.");break;
  455.  
  456. default:sprintf(tipoftheday,"Tip Of The Day: See html doc included to see help and pattern commands.");break;
  457. }
  458.  
  459. L_MaxLevel=0;
  460. R_MaxLevel=0;
  461.  
  462.    if (!S->isModeAvailable(CONSOLE_WIDTH,CONSOLE_HEIGHT))
  463.    {
  464.        MessageBox(NULL,"Screen resolution is not supported on your gfxcard","Error!",MB_OK);
  465.     return -1;
  466.   }
  467.  
  468.   HICON icon=(HICON)LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_UFO),IMAGE_ICON,0,0,0);
  469.   setWindowIcon(icon);
  470.   setWindowTitle("NoiseTrekker");
  471.   Width=CONSOLE_WIDTH;
  472.   Height=CONSOLE_HEIGHT;
  473.   
  474.   if (GUIMODE)
  475.   {FullScreen=0;Flags=WindowsFrame+SingleBuffer;}
  476.   else
  477.   {FullScreen=1;Flags=SingleBuffer;}
  478.   
  479.   sprintf(name,"Untitled");
  480.   sprintf(artist,"Somebody");
  481.   sprintf(style,"Goa Trance");
  482.  
  483.   namesize=8;
  484.   IniCsParNames();
  485.   for (unsigned int listcleaner=0;listcleaner<2048;listcleaner++){for (int listcleaner2=0;listcleaner2<64;listcleaner2++){SMPT_LIST[listcleaner][listcleaner2]=0;}}
  486.   
  487.   Read_SMPT();
  488.   init_sample_bank();
  489.   BuffPatt=(unsigned char *)malloc(12288);
  490.   BuffTrack=(unsigned char *)malloc(768);
  491.   BuffBlock=(unsigned char *)malloc(12288);
  492.   
  493.   for (int ipcut=0;ipcut<360;ipcut++)
  494.     SIN[ipcut]=(float)sin((float)ipcut*0.0174532f);
  495.   
  496.   for (ipcut=0;ipcut<384;ipcut+=6)
  497.   {
  498.     *(BuffTrack+ipcut)=121;
  499.     *(BuffTrack+ipcut+1)=255;
  500.     *(BuffTrack+ipcut+2)=255;
  501.     *(BuffTrack+ipcut+3)=255;
  502.     *(BuffTrack+ipcut+4)=0;
  503.     *(BuffTrack+ipcut+5)=0;
  504.   }    
  505.  
  506.   for (ipcut=0;ipcut<12288;ipcut+=6)
  507.     {
  508.     *(BuffPatt+ipcut)=121;
  509.     *(BuffPatt+ipcut+1)=255;
  510.     *(BuffPatt+ipcut+2)=255;
  511.     *(BuffPatt+ipcut+3)=255;
  512.     *(BuffPatt+ipcut+4)=0;
  513.     *(BuffPatt+ipcut+5)=0;
  514.     *(BuffBlock+ipcut)=121;
  515.     *(BuffBlock+ipcut+1)=255;
  516.     *(BuffBlock+ipcut+2)=255;
  517.     *(BuffBlock+ipcut+3)=255;
  518.     *(BuffBlock+ipcut+4)=0;
  519.     *(BuffBlock+ipcut+5)=0;
  520.     }
  521.  
  522.   float ve=0;
  523.  
  524. Initreverb();
  525.  
  526. setPostAction(postAction);  
  527.   return 0;
  528. }
  529.  
  530. // Work Function ------------------------------------------------
  531.  
  532. class SineWave : public InputFilter
  533. {
  534. public:
  535. virtual int Read(char* Buffer, int Len)
  536. {
  537. short *pSamples=(short *)Buffer;
  538.  
  539. if(!rawrender)
  540. {
  541.     int i;
  542.     switch(QUALITYPLAY){
  543.     case 0:
  544.     for(i=Len-1;i>=0;i-=4){
  545.     GetPlayerValues(mas_vol);
  546.     *pSamples++=left_value;
  547.     *pSamples++=right_value;
  548.     if (left_value>L_MaxLevel)L_MaxLevel=left_value;
  549.     if (right_value>R_MaxLevel)R_MaxLevel=right_value;
  550.     Lscope[Cscope]=left_value;
  551.     Rscope[Cscope]=right_value;
  552.     if(left_value<-32760 || left_value>32760 || right_value<-32760 || right_value>32760)clipc=0xFFDD;
  553.     Cscope++;
  554.     if (Cscope>127){Cscope=0;
  555.     if(L_MaxLevel>128)L_MaxLevel-=128;
  556.     if(R_MaxLevel>128)R_MaxLevel-=128;}}
  557.     break;
  558.  
  559.     case 1:
  560.     for(i=Len-1;i>=0;i-=4){
  561.     GetPlayerValues2(mas_vol);
  562.     *pSamples++=left_value;
  563.     *pSamples++=right_value;   
  564.     if(left_value<-32760 || left_value>32760 || right_value<-32760 || right_value>32760)clipc=0xFFDD; 
  565.     if (left_value>L_MaxLevel)L_MaxLevel=left_value;
  566.      if (right_value>R_MaxLevel)R_MaxLevel=right_value;
  567.      if(L_MaxLevel)L_MaxLevel--;
  568.      if(R_MaxLevel)R_MaxLevel--;}
  569.     break;
  570.  
  571.     case 2:
  572.     for(i=Len-1;i>=0;i-=4){
  573.     GetPlayerValues3(mas_vol);
  574.     *pSamples++=left_value;
  575.     *pSamples++=right_value;
  576.     if(left_value<-32760 || left_value>32760 || right_value<-32760 || right_value>32760)clipc=0xFFDD;
  577.      if (left_value>L_MaxLevel)L_MaxLevel=left_value;
  578.      if (right_value>R_MaxLevel)R_MaxLevel=right_value;
  579.      if(L_MaxLevel)L_MaxLevel--;
  580.      if(R_MaxLevel)R_MaxLevel--;}
  581.     break;
  582. }// SWITCH
  583. }//RawRender
  584. //if(hd_isrecording){for(int wo=0;wo<Len;wo++)fputc(*(Buffer+wo),HDSTREAM);}
  585.     
  586. return Len;
  587. }
  588.  
  589. }; // CLASS SINEWAVE
  590.  
  591. SoundStream* ss=NULL;
  592. SineWave*    sw=NULL;
  593.  
  594. // Action Loop .-------------------------------------------------
  595.  
  596. int action(Console* C)
  597. {
  598.     
  599. S=C->getScreen();
  600. redraw_everything=0;
  601.  
  602. if (CON_Reactivated())  // screen has been erased
  603. {
  604. redraw_everything=1;
  605.  
  606. MemoryInputStream mis((char*)CompressedPointerBitmap,sizeof(CompressedPointerBitmap));
  607. InflateStream is(mis);
  608. Bitmap* BM=newBitmap(is);
  609. TColor Color=C->getScreen()->getColor(0,0,0xf8);
  610. BM->setTransparentColor(Color);
  611. C->getMouse()->setPointer(BM,1,1);
  612. RELEASEINT(BM);
  613. }
  614.  
  615.   if (ss==NULL)
  616.   {
  617.     MidiGetAll();                /* Retrieves Midi Info */
  618.     Iniplayer();                /* Player initialization */
  619.     sw=new SineWave();
  620.     ss=newSoundStream(sw,44100,16,2,1);
  621.     ss->setFrameSize(10);
  622.     ss->setStreamDelay(XLATENCY_TIME);
  623.     ss->play();
  624.     ss->setVolume(0);
  625.     S->setGammaFade(1.0f,1.0f,1.0f);
  626.     MOUSEBACK=newBitmap(12,20,0);
  627.     NTKLOGO=loadBMP("skin/ntk.bmp");
  628.     SKIN303=loadBMP("skin/ntk303.bmp");
  629.     KNOB1=loadBMP("skin/knob1.bmp");
  630.     PFONT=loadBMP("skin/patternfont.bmp");
  631.     FRAMEWORK=loadBMP("skin/framework2.bmp");
  632.  
  633.     C->getSound()->setPreferences(44100,16,2);
  634.   }
  635.  
  636.   if (clrc==0)
  637.   {
  638.   S->clear(0);
  639.   MOUSEBACK->clear(0);
  640.   clrc=1;
  641.   }
  642.  
  643.   if (S->lock()==0)
  644.   {
  645.  
  646.     if (userscreen==4 && Scopish)DrawScope();
  647.     
  648.     if (sp_Stage[ped_track] && ped_patsam==sp_channelsample[ped_track] && ped_split==sp_split[ped_track])
  649.     {draw_sampled_wave2=true;
  650.     boing=true;
  651.     }
  652.     else if (boing)
  653.     {
  654.         boing=false;
  655.         draw_sampled_wave3=true;
  656.     }
  657.  
  658.     
  659.     Draw_Sampled_Wave();
  660.     Draw_Sampled_Wave2();
  661.     Draw_Sampled_Wave3();
  662.  
  663.       int Lt_vu=80+L_MaxLevel/64;
  664.     int Rt_vu=80+R_MaxLevel/64;
  665.  
  666.     if(redraw_everything==1)
  667.     {
  668.     for(int nx=0;nx<CONSOLE_HEIGHT;nx++)
  669.     S->drawHLine(nx,0,CONSOLE_WIDTH,0);
  670.     }
  671.  
  672.     S->drawHLine(11,80,Lt_vu,0xDD00);
  673.     S->drawHLine(12,80,Lt_vu,0xFF00);
  674.     
  675.     S->drawHLine(17,80,Rt_vu,0xDD00);
  676.     S->drawHLine(18,80,Rt_vu,0xFF00);
  677.     
  678.     S->drawHLine(11,Lt_vu,584,clipc);
  679.     S->drawHLine(12,Lt_vu,584,clipc);
  680.     
  681.     S->drawHLine(17,Rt_vu,584,clipc);
  682.     S->drawHLine(18,Rt_vu,584,clipc);
  683.     
  684.     if (actuloop)Afloop();
  685.  
  686.     S->unlock();
  687.  
  688.     
  689.   }
  690.  
  691.   if (gui_action!=0)vloid();
  692.   if (S->beginDraw()==0)
  693.   {
  694.     dc=(HDC)S->getDeviceContext();
  695.     fnt=CreateFont(8,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"MS Sans Serif");
  696.     old_f=(HFONT)SelectObject(dc,fnt);
  697.  
  698. if (gui_action!=0) // There are some for me today.....:)
  699. {
  700.     if (gui_action==1)
  701.     {
  702.         lt_ykar=LastY-72;
  703.         ltActualize(0);
  704.     }
  705.  
  706.     if (gui_action==2)
  707.     {
  708.         int broadcast=lt_index+(LastY-44)/12;
  709.         last_index=-1;
  710.         if (broadcast!=lt_curr)
  711.         {
  712.             lt_curr=broadcast;
  713.             ltActualize(1);
  714.         }
  715.         else
  716.         {
  717.             if (FILETYPE[lt_curr]!=_A_SUBDIR)
  718.             {
  719.             ss->stop();
  720.             StopIfSp();
  721.             WavAlloc(ped_patsam,SMPT_LIST[lt_curr]);
  722.             ss->play();
  723.             }
  724.             else
  725.             {
  726.                 _chdir(SMPT_LIST[lt_curr]);
  727.                 Read_SMPT();
  728.                 ltActualize(0);
  729.  
  730.             }
  731.             
  732.         }
  733.     }
  734.  
  735.     if (gui_action==3){cPosition--;Actualize_Sequencer();Actupated(0);}
  736.     if (gui_action==4){cPosition++;Actualize_Sequencer();Actupated(0);}
  737.     if (gui_action==5){Actualize_Sequencer();Actupated(0);}
  738.     if (gui_action==7){pSequence[cPosition]--;Actualize_Sequencer();Actupated(0);Anat(cPosition);}
  739.     if (gui_action==8){pSequence[cPosition]++;Actualize_Sequencer();Actupated(0);Anat(cPosition);}
  740.     if (gui_action==9){sLength--;Actualize_Sequencer();}
  741.     if (gui_action==10){sLength++;Actualize_Sequencer();}
  742.     if (gui_action==11){Actualize_Sequencer();}
  743.     
  744.     if (gui_action==15){Actualize_Track_Ed(0);Actualize_Lfo_Ed(0);}
  745.     if (gui_action==16){Actualize_Track_Ed(0);Actualize_Lfo_Ed(0);}
  746.  
  747.     if (gui_action==21){ped_patoct--;Actualize_Patterned();}
  748.     if (gui_action==22){ped_patoct++;Actualize_Patterned();}
  749.     if (gui_action==23){ped_pattad--;Actualize_Patterned();}
  750.     if (gui_action==24){ped_pattad++;Actualize_Patterned();}
  751.     
  752.     if (gui_action==25)
  753.     {
  754.     ped_patsam--;
  755.  
  756.     if(snamesel==2)
  757.         snamesel=0;
  758.     
  759.     Actualize_Patterned();
  760.     RefreshSample();
  761.     NewWavy();
  762.     Actualize_Wave_Ed(0);
  763.     if (userscreen==6)
  764.     Actualize_Midi_Ed(1);
  765.     }
  766.     
  767.     if (gui_action==26)
  768.     {
  769.         ped_patsam++;
  770.         
  771.         if(snamesel==2)
  772.             snamesel=0;
  773.         
  774.         Actualize_Patterned();
  775.         RefreshSample();
  776.         NewWavy();
  777.         Actualize_Wave_Ed(0);
  778.         
  779.     if (userscreen==6)
  780.     Actualize_Midi_Ed(1);
  781.     }
  782.     
  783.     if (gui_action==27)
  784.     {
  785.     int tmp_track=gui_track+((LastX-24)/118);
  786.     
  787.     if (tmp_track>15)tmp_track=15;
  788.     if (tmp_track<0)tmp_track=0;
  789.  
  790.     if (TRACKSTATE[tmp_track]==0)
  791.     TRACKSTATE[tmp_track]=1;
  792.     else
  793.     TRACKSTATE[tmp_track]=0;
  794.     
  795.     if(userscreen==1)Actualize_Track_Ed(10);
  796.     Actupated(0);
  797.     }
  798.  
  799.     
  800.  
  801.     if (gui_action==28){SongPlay();}
  802.     if (gui_action==29){SongStop();Actupated(0);}
  803.     if (gui_action==30){StartRec();}
  804.     if (gui_action==40){Actualize_Master(teac);}
  805.     if (gui_action==50){TCut[ped_track]=float(LastX-88);Actualize_Track_Ed(1);liveparam=1;livevalue=(LastX-88)*2;}   
  806.     if (gui_action==51){FRez[ped_track]=LastX-88;Actualize_Track_Ed(2);liveparam=2;livevalue=(LastX-88)*2;}
  807.     if (gui_action==52){ICut[ped_track]=(LastX-88.0f)*0.00006103515625f;Actualize_Track_Ed(3);}
  808.     if (gui_action==53){Actualize_Track_Ed(teac);}
  809.     if (gui_action==54){DThreshold[ped_track]=float((LastX-318)*512);Actualize_Track_Ed(7);liveparam=4;livevalue=(LastX-318)*2;}
  810.     if (gui_action==55){DClamp[ped_track]=float((LastX-318)*512);Actualize_Track_Ed(8);liveparam=5;livevalue=(LastX-318)*2;}
  811.     if (gui_action==56){DSend[ped_track]=float(((float)LastX-318)/128.0);Actualize_Track_Ed(5);liveparam=3;livevalue=(LastX-318)*2;}
  812.     if (gui_action==57){TPan[ped_track]=((float)LastX-318)/128.0f;Actualize_Track_Ed(9);liveparam=6;livevalue=LastX-318;}
  813.     if (gui_action==60){userscreen=0;draw_mained();Actualize_Main_Ed();}
  814.     if (gui_action==61){userscreen=1;draw_tracked();Actualize_Track_Ed(0);}
  815.     if (gui_action==62){userscreen=2;draw_sampleed();Actualize_Sample_Ed(2,0);}
  816.     if (gui_action==63){userscreen=3;draw_fxed();Actualize_Fx_Ed(teac);}
  817.     if (gui_action==64){userscreen=4;draw_seqed();Actualize_Seq_Ed();}
  818.     if (gui_action==65){userscreen=5;draw_mastered();Actualize_Master_Ed(0);}
  819.     if (gui_action==66){userscreen=6;draw_midied();Actualize_Midi_Ed(0);}
  820.     if (gui_action==67){userscreen=7;draw_lfoed();Actualize_Lfo_Ed(teac);}
  821.     if (gui_action==68){userscreen=8;draw_exted();}
  822.     if (gui_action==69){draw_back();}
  823.     if (gui_action==70){SaveInst();}
  824.     if (gui_action==71){ShowInfo();}
  825.     if (gui_action==72){userscreen=9;draw_303ed();}
  826.     if (gui_action==73){Actualize_303ed(teac);}
  827.  
  828.     if (gui_action==100){ltActualize(1);}
  829.     if (gui_action==101){Actualize_Sample_Ed(1,teac);}
  830.     if (gui_action==102){SaveMod();}
  831.     if (gui_action==103){LoadMod();}
  832.     if (gui_action==104){SampleVol[ped_patsam][ped_split]=float((LastX-436)/32.0);Actualize_Sample_Ed(0,1);}
  833.     if (gui_action==105){Finetune[ped_patsam][ped_split]=((LastX-436)-64)*2;Actualize_Sample_Ed(0,2);}
  834.     if (gui_action==106){FDecay[ped_patsam][ped_split]=float(LastX-62)/8192.0f;Actualize_Sample_Ed(0,3);}
  835.     if (gui_action==107){Actualize_Sample_Ed(0,teac);}
  836.     if (gui_action==108){Actualize_Main_Ed();}
  837.     if (gui_action==109){Newmod();}
  838.     if (gui_action==110){Actualize_Seq_Ed();}
  839.     if (gui_action==111){Actualize_Seq_Ed();Actualize_Sequencer();}
  840.     if (gui_action==112){Actualize_Fx_Ed(teac);}
  841.     if (gui_action==113){shuffle=LastX-62;Actualize_Master_Ed(4);}
  842.     if (gui_action==114){Actualize_Master_Ed(teac);}
  843.     if (gui_action==150){Actualize_Midi_Ed(teac);}
  844.     if (gui_action==151){mess_box("All Notes Off command send on this track...");}
  845.     if (gui_action==152){mess_box("All Notes Off command send on all tracks...");}
  846.     if (gui_action==153){mess_box("Panic pressed!");}
  847.     if (gui_action==154){Actualize_Lfo_Ed(teac);}
  848.     if (gui_action==125){ped_patsam-=16;Actualize_Patterned();RefreshSample();NewWavy();if (userscreen==6)Actualize_Midi_Ed(1);}
  849.     if (gui_action==126){ped_patsam+=16;Actualize_Patterned();RefreshSample();NewWavy();if (userscreen==6)Actualize_Midi_Ed(1);}
  850.     if (gui_action==129){Actualize_Patterned();}
  851.  
  852.     if (gui_action==115)
  853.     {
  854.         if (pSequence[cPosition]>9)
  855.         pSequence[cPosition]-=10;
  856.         else
  857.         pSequence[cPosition]=0;
  858.         
  859.         Anat(cPosition);
  860.         Actualize_Sequencer();
  861.         Actupated(0);
  862.     }
  863.     
  864.     if (gui_action==116)
  865.     {
  866.         if (pSequence[cPosition]<118)
  867.         pSequence[cPosition]+=10;
  868.         else
  869.         pSequence[cPosition]=127;
  870.         Anat(cPosition);
  871.         
  872.         Actualize_Sequencer();
  873.         Actupated(0);
  874.     }
  875.  
  876.     if (gui_action==169){RawRenderizer();}
  877.  
  878.     if (gui_action==200){Actualize_Sequencer();player_pos=cPosition;}
  879.     if (gui_action==201){DeleteInstrument();}
  880.     if (gui_action==202){SaveSynth();}
  881.     if (gui_action==203){LoadSynth();}
  882.     if (gui_action==204){mess_box("There're no more patterns allocated.");}
  883.     if (gui_action==205){Actualize_Scopish();}
  884.     if (gui_action==206){RandSynth();}
  885.  
  886.     if (gui_action==210){Actualize_Wave_Ed(teac);}
  887.     
  888.     if (gui_action==254){
  889.     SongStop();
  890.     mess_box("Returning to windows...");
  891.     Sleep(1000);
  892.     ss->stop();
  893.     mess_box("All memory cleaned.");
  894.     FadeToBlack();
  895.     S->setColor(0,0,0);
  896.     bjbox(0,0,CONSOLE_WIDTH,CONSOLE_HEIGHT);
  897.     S->endDraw();
  898.     return 1;}
  899.  
  900.     gui_action=255;
  901. }
  902.     
  903.   if (clrc==1 || redraw_everything==1)
  904.     {
  905.         userscreen=0;
  906.         last_index=-1;
  907.         guiDial3(0,6,fsize,16,"Audio Vumeter:",200);
  908.         guiDial3(0,24,392,16,"NOISETREKKER R13 By Juan Antonio Arguelles Rius <arguru@vermail.net>",200);
  909.         mess_box(tipoftheday);
  910.         guiDial3(394,24,58,16,"Current Dir:",200);
  911.         guiDial(394,42,16,14,"-",200);
  912.         guiDial(394,162,16,14,"+",200);
  913.         guiDial3(0,178,fsize,4,"",200);
  914.         guiDial3(0,309,110,16,"User Window",200);
  915.         guiDial3(0,42,96,80,"Player",128);
  916.         guiDial(8,60,80,16,"Play Sng/Pttrn",200);
  917.          guiDial(8,78,80,16,"Slider Rec: OFF",200);
  918.         guiDial(8,96,80,16,"Stop     ",200);
  919.         guiDial3(256,42,136,80,"Song Settings",128);
  920.         guiDial3(0,327,fsize,122,"",144);
  921.         guiDial3(262,60,60,16,"Tracks",200);
  922.         guiDial3(262,78,60,16,"B.P.M.",200);
  923.         guiDial3(262,96,60,16,"T.P.B.",200);
  924.         if(restx>0)guiDial3(772,309,restx-2,16,"",200);
  925.  
  926.         guiDial3(98,42,156,80,"Sequence",128);
  927.         guiDial3(106,60,80,16,"Position",200);
  928.         guiDial3(106,78,80,16,"Pattern",200);
  929.         guiDial3(106,96,80,16,"Song Length",200);
  930.         
  931.         guiDial3(512,458,CONSOLE_WIDTH-514,CONSOLE_HEIGHT-482,"Sample Editor [v0.8]",144);        
  932.         
  933.         guiDial(516,476,29,16,"Cut",200);
  934.         guiDial(547,476,29,16,"Half",200);
  935.         guiDial(516,494,60,16,"Maximize",200);
  936.         guiDial(516,512,60,16,"DC Adjust",200);
  937.         guiDial(516,530,60,16,"Fade In",200);
  938.         guiDial(516,548,60,16,"Fade Out",200);
  939.         
  940.         guiDial(578,476,60,16,"Select All",200);
  941.         guiDial(578,494,60,16,"Unselect",200);
  942.         
  943.         guiDial(578,512,60,16,"View All",170);
  944.         guiDial(578,530,60,16,"VZoom In",200);
  945.         guiDial(578,548,60,16,"VZoom Out",200);
  946.  
  947.         NewWavy();
  948.         guiDial(646,476,60,16,"Zoom In",200);
  949.         guiDial(646,494,60,16,"Zoom Out",200);
  950.  
  951.         guiDial(708,476,60,16,"Set Loop S.",200);
  952.         guiDial(708,494,60,16,"Set Loop E.",200);
  953.         
  954.         guiDial3(646,520,60,16,"Range",200);
  955.         guiDial3(708,520,60,16,"View",200);
  956.         
  957.         guiDial3(0,452,fsize,4,"",200);
  958.         guiDial3(0,124,392,52,"",128);
  959.         guiDial3(8,152,80,16,"Step Add",200);
  960.          guiDial3(166,152,90,16,"Keyboard Octave",200);
  961.         guiDial3(8,134,80,16,"Instrument",200);
  962.         guiDial(320,134,64,16,"Delete",200);
  963.         draw_mained();
  964.         Actualize_Sequencer();
  965.         Actualize_Patterned();
  966.         Actualize_Master(0);
  967.         Actualize_Main_Ed();
  968.  
  969.         ltActualize(0);
  970.         S->fillRect(79,10,601,14);
  971.         S->fillRect(79,16,601,20);
  972.         guiDial3(106,114,80,16,"Pattern Lines",200);
  973.                 
  974.         
  975.         if (clrc==1){
  976.         AllocPattern();
  977.         clrc=2;
  978.         }
  979.         
  980.         LastX=C->getMouse()->getX();
  981.         LastY=C->getMouse()->getY();
  982.         actlogo=true;
  983.     }
  984.   if (Songplaying==1 && ped_line!=player_line)
  985.   {
  986.       Actupated(0);
  987.       player_line=ped_line;
  988.   }
  989.  
  990.   SelectObject(dc,old_f);DeleteObject(fnt);
  991.   S->endDraw();  
  992. }
  993.  
  994. if(NTKLOGO!=NULL && actlogo==true)
  995. {
  996. S->copy(NTKLOGO, 656, 338);actlogo=false;
  997. S->copy(FRAMEWORK, 0, 184);
  998. Actupated(0);
  999. }
  1000.  
  1001. if(act303!=0)
  1002. {
  1003.     Actualize_303(act303);
  1004.     act303=0;
  1005. }
  1006. // Checking for mouse events ------------------------------------
  1007.  
  1008.   long rc;
  1009.  
  1010. if (gui_action==255)
  1011. {
  1012. if(!GUIMODE)
  1013. {MOUSEBACK->copy(S, 0, 0,LastX-1,LastY-1, LastX+10,LastY+18,0);
  1014. C->getMouse()->render();}
  1015.  
  1016. gui_action=0;
  1017. }
  1018.  
  1019. teac=0;
  1020.  
  1021. if (userscreen==2 && seditor==1 && C->getMouse()->leftButton())
  1022. {
  1023. gui_action=255;
  1024. if (zcheckMouse(78,350,16,16) && LoopStart[ped_patsam][ped_split]>0){LoopStart[ped_patsam][ped_split]--;gui_action=107;teac=5;}
  1025. if (zcheckMouse(194,350,16,16) && LoopStart[ped_patsam][ped_split]<LoopEnd[ped_patsam][ped_split]){LoopStart[ped_patsam][ped_split]++;gui_action=107;teac=5;}
  1026. if (zcheckMouse(278,350,16,16) && LoopEnd[ped_patsam][ped_split]>LoopStart[ped_patsam][ped_split]){LoopEnd[ped_patsam][ped_split]--;gui_action=101;teac=5;}
  1027. if (zcheckMouse(394,350,16,16) && LoopEnd[ped_patsam][ped_split]<SampleNumSamples[ped_patsam][ped_split]-1){LoopEnd[ped_patsam][ped_split]++;gui_action=101;teac=5;}
  1028. }
  1029.  
  1030. while((rc=C->getMouse()->getEvent(1,24,mlimit,CONSOLE_HEIGHT2))!=0)
  1031.   {
  1032.       if (rc==1)// mouse moved, do something
  1033.       {
  1034.         //Mouse Move Handling       
  1035.         vloid();
  1036.         LastX=C->getMouse()->getX();
  1037.         LastY=C->getMouse()->getY();
  1038.         if(!GUIMODE)
  1039.         {MOUSEBACK->copy(S, 0, 0,LastX-1,LastY-1, LastX+10,LastY+18,0);
  1040.         C->getMouse()->render();}
  1041.  
  1042.       }
  1043.  
  1044. if (C->getMouse()->leftButton())
  1045. {
  1046.     gui_action=255;
  1047.  
  1048.     if (zcheckMouse(395,59,16,103)){gui_action=1;}
  1049.  
  1050. if(userscreen==9)
  1051. {
  1052.  
  1053.     // Volume Knob
  1054.     if (zcheckMouse(529,357,19,88))
  1055.     {
  1056.         int breakvol=88-(LastY-357);
  1057.         if(breakvol<0)breakvol=0;
  1058.         if(breakvol>86)breakvol=86;
  1059.         tb303engine[sl3].tbVolume=breakvol*0.01136363636f;
  1060.         gui_action=73;
  1061.         teac=15;
  1062.     }
  1063.  
  1064.         // Tune Knob
  1065.     if (zcheckMouse(229,348,24,24))
  1066.     {
  1067.         if(fluzy==-1)fluzy=LastY+tb303[sl3].tune;
  1068.  
  1069.         int tempz=fluzy-LastY;
  1070.         if (tempz<0)tempz=0;
  1071.         if (tempz>127)tempz=127;
  1072.         tb303[sl3].tune=tempz;
  1073.         gui_action=73;
  1074.         teac=3;
  1075.     }
  1076.     
  1077.     // CutOff Knob
  1078.     if (zcheckMouse(262,348,24,24))
  1079.     {
  1080.         if(fluzy==-1)fluzy=LastY+tb303[sl3].cutoff;
  1081.  
  1082.         int tempz=fluzy-LastY;
  1083.         if (tempz<0)tempz=0;
  1084.         if (tempz>127)tempz=127;
  1085.         tb303[sl3].cutoff=tempz;
  1086.         gui_action=73;
  1087.         teac=4;
  1088.         liveparam=7+sl3;
  1089.         livevalue=tempz<<1;
  1090.     }
  1091.  
  1092.     // Reso knob
  1093.     if (zcheckMouse(295,348,24,24))
  1094.     {
  1095.         if(fluzy==-1)fluzy=LastY+tb303[sl3].resonance;
  1096.  
  1097.         int tempz=fluzy-LastY;
  1098.         if (tempz<0)tempz=0;
  1099.         if (tempz>127)tempz=127;
  1100.         tb303[sl3].resonance=tempz;
  1101.         gui_action=73;
  1102.         teac=5;
  1103.         liveparam=9+sl3;
  1104.         livevalue=tempz<<1;
  1105.     }
  1106.  
  1107.     // Envmod knob
  1108.     if (zcheckMouse(328,348,24,24))
  1109.     {
  1110.         if(fluzy==-1)fluzy=LastY+tb303[sl3].envmod;
  1111.  
  1112.         int tempz=fluzy-LastY;
  1113.         if (tempz<0)tempz=0;
  1114.         if (tempz>127)tempz=127;
  1115.         tb303[sl3].envmod=tempz;
  1116.         gui_action=73;
  1117.         teac=6;
  1118.         liveparam=11+sl3;
  1119.         livevalue=tempz<<1;
  1120.     }
  1121.  
  1122.     // Decay knob
  1123.     if (zcheckMouse(361,348,24,24))
  1124.     {
  1125.         if(fluzy==-1)fluzy=LastY+tb303[sl3].decay;
  1126.  
  1127.         int tempz=fluzy-LastY;
  1128.         if (tempz<0)tempz=0;
  1129.         if (tempz>127)tempz=127;
  1130.         tb303[sl3].decay=tempz;
  1131.         gui_action=73;
  1132.         teac=7;
  1133.         liveparam=13+sl3;
  1134.         livevalue=tempz<<1;
  1135.     }
  1136.  
  1137.     // Accent knob
  1138.     if (zcheckMouse(394,348,24,24))
  1139.     {
  1140.         if(fluzy==-1)fluzy=LastY+tb303[sl3].accent;
  1141.  
  1142.         int tempz=fluzy-LastY;
  1143.         if (tempz<0)tempz=0;
  1144.         if (tempz>127)tempz=127;
  1145.         tb303[sl3].accent=tempz;
  1146.         gui_action=73;
  1147.         teac=8;
  1148.     }
  1149. }
  1150.  
  1151.     if (zcheckMouse(0,458,512,CONSOLE_HEIGHT2))
  1152.     {
  1153.     if (SampleType[ped_patsam][ped_split])
  1154.     {
  1155.     axswave=SampleNumSamples[ped_patsam][ped_split]-1;
  1156.     sed_range_mode=true;
  1157.     sed_range_end=sed_display_start+((LastX-1)*sed_display_length)/512;
  1158.     teac=4;
  1159.  
  1160.     if (!sas)
  1161.     {
  1162.     sed_range_start=sed_range_end;
  1163.     teac=5;
  1164.     }
  1165.     
  1166.     if (sed_range_start<sed_display_start)
  1167.     {
  1168.         sed_range_start=sed_display_start;
  1169.         teac=5;
  1170.     }
  1171.  
  1172.     if(sed_range_end<=sed_range_start)
  1173.     {
  1174.     long erebus=sed_range_start;
  1175.     sed_range_start=sed_range_end;
  1176.     sed_range_end=erebus;
  1177.     teac=5;
  1178.     }
  1179.     
  1180.     if (sed_range_end>axswave)sed_range_end=axswave;
  1181.     gui_action=210;
  1182.     draw_sampled_wave=true;
  1183.     sas=true;
  1184.     }//SAMPLETYPE
  1185.     }//MOUSEBOX
  1186.     
  1187.     if (userscreen==2 && SampleType[ped_patsam][ped_split]!=0)
  1188.     {
  1189.     if (zcheckMouse(426,408,148,18)){gui_action=104;}
  1190.     if (zcheckMouse(436,426,128,18)){gui_action=105;}
  1191.     if (zcheckMouse(52,408,148,18)){gui_action=106;}
  1192.     if (zcheckMouse(52,426,148,18)){CustomVol[ped_patsam]=float(LastX-62)*0.0078125f;gui_action=107;teac=15;}
  1193.     }
  1194.  
  1195.     if (userscreen==5)
  1196.     {
  1197.     if (zcheckMouse(52,420,148,18)){gui_action=113;}
  1198.     if (zcheckMouse(252,366,148,18)){mas_vol=(LastX-262.0f)/128.0f;gui_action=114;teac=2;}
  1199.     if (zcheckMouse(252,384,48,16) && !AMIMODE){AMIMODE=true;gui_action=114;teac=5;}
  1200.     if (zcheckMouse(300,384,48,16) && AMIMODE){AMIMODE=false;gui_action=114;teac=5;}
  1201.     }
  1202.  
  1203.     
  1204.     if (userscreen==6)
  1205.     {
  1206.     if (zcheckMouse(406,388,148,18))
  1207.             {csynth_slv=LastX-416;
  1208.             if (csynth_slv<0)csynth_slv=0;
  1209.             if (csynth_slv>128)csynth_slv=128;
  1210.             teac=6;gui_action=150;}
  1211.     }
  1212.  
  1213.     if (userscreen==7)
  1214.     {
  1215.     if (zcheckMouse(74,362,148,18)){LFORATE[ped_track]=(LastX-84)/16384.0f;teac=2;gui_action=154;}
  1216.     if (zcheckMouse(74,380,148,18)){LFOAMPL[ped_track]=float(LastX-84);teac=3;gui_action=154;}
  1217.     if (zcheckMouse(74,416,148,18)){FLANGER_DEPHASE[ped_track]=(LastX-84)*0.0490873f;teac=4;gui_action=154;teac=4;}
  1218.  
  1219.     if (zcheckMouse(298,350,148,18)){teac=1;FLANGER_AMOUNT[ped_track]=((LastX-308.0f)/64.0f)-1.0f;gui_action=154;}
  1220.     if (zcheckMouse(298,368,148,18)){FLANGER_RATE[ped_track]=(LastX-308.0f)/939104.92f;gui_action=154;teac=5;}
  1221.     if (zcheckMouse(298,386,148,18)){FLANGER_AMPL[ped_track]=(LastX-308.0f)/12800.0f;gui_action=154;teac=6;}
  1222.     if (zcheckMouse(298,404,148,18)){FLANGER_FEEDBACK[ped_track]=((LastX-308)/64.0f)-1.0f;gui_action=154;teac=7;}
  1223.     if (zcheckMouse(298,422,148,18)){FLANGER_DELAY[ped_track]=(LastX-308)*32;gui_action=154;fld_chan=true;teac=8;}
  1224.     }
  1225.     if (userscreen==1)
  1226.     {
  1227.     if (zcheckMouse(78,360,148,18)){gui_action=50;}
  1228.     if (zcheckMouse(78,378,148,18)){gui_action=51;}
  1229.     if (zcheckMouse(78,414,148,18)){gui_action=52;}
  1230.     if (zcheckMouse(308,360,148,18)){gui_action=54;}
  1231.     if (zcheckMouse(308,378,148,18)){gui_action=55;}
  1232.     if (zcheckMouse(308,396,148,18)){gui_action=56;}
  1233.     if (zcheckMouse(308,414,148,18)){gui_action=57;}
  1234.         
  1235.     }
  1236.  
  1237.     if (userscreen==3)
  1238.     {
  1239.     if (zcheckMouse(78,378,148,18))
  1240.     {
  1241.         Feedback=float(float(LastX-88)/127.0);
  1242.         if (Feedback<0)Feedback=0;
  1243.         if (Feedback>0.99f)Feedback=0.99f;
  1244.         Feedback5=Feedback;
  1245.         Feedback4=Feedback;
  1246.         Feedback3=Feedback;
  1247.         Feedback2=Feedback;
  1248.  
  1249.         gui_action=112;
  1250.         
  1251.         teac=2;}
  1252.     if (zcheckMouse(78,414,148,18)){c_threshold=LastX-88;gui_action=112;teac=7;}
  1253.     if (zcheckMouse(78,432,148,18)){REVERBFILTER=(float)(LastX-88)/128.0f;gui_action=112;teac=9;}    
  1254.     if (zcheckMouse(308,360,148,18)){lchorus_delay=(LastX-318)*174;gui_action=112;teac=3;}
  1255.     if (zcheckMouse(308,378,148,18)){rchorus_delay=(LastX-318)*174;gui_action=112;teac=4;}
  1256.     if (zcheckMouse(308,396,148,18)){lchorus_feedback=float(LastX-318)/127;gui_action=112;teac=5;}
  1257.     if (zcheckMouse(308,414,148,18)){rchorus_feedback=float(LastX-318)/127;gui_action=112;teac=6;}
  1258.  
  1259.     }// userscreen
  1260.  
  1261. // Check Zones for GUI clicks -----------------------------------
  1262.  
  1263.     if (rc==2) // left mouse button (de)pressed, check state and act.
  1264.     {
  1265.     
  1266.         #include "303guicode.cpp"
  1267.  
  1268.         if (SampleType[ped_patsam][ped_split])
  1269.         {
  1270.         if (zcheckMouse(708,476,60,16) && sed_range_mode){
  1271.         LoopStart[ped_patsam][ped_split]=sed_range_start;
  1272.         
  1273.         if (LoopStart[ped_patsam][ped_split]>LoopEnd[ped_patsam][ped_split])
  1274.             LoopEnd[ped_patsam][ped_split]=LoopStart[ped_patsam][ped_split];
  1275.         
  1276.         if(LoopType[ped_patsam][ped_split]==0)
  1277.         {
  1278.         LoopType[ped_patsam][ped_split]=1;
  1279.         LoopEnd[ped_patsam][ped_split]=SampleNumSamples[ped_patsam][ped_split]-1;
  1280.         }
  1281.  
  1282.         draw_sampled_wave=true;
  1283.         if (userscreen==2){gui_action=107;teac=5;}
  1284.         }
  1285.  
  1286.         if (zcheckMouse(708,494,60,16) && sed_range_mode){
  1287.         LoopEnd[ped_patsam][ped_split]=sed_range_end;
  1288.         
  1289.         if (LoopEnd[ped_patsam][ped_split]<LoopStart[ped_patsam][ped_split])
  1290.             LoopStart[ped_patsam][ped_split]=LoopEnd[ped_patsam][ped_split];
  1291.                 
  1292.         if(LoopType[ped_patsam][ped_split]==0)
  1293.         {
  1294.         LoopType[ped_patsam][ped_split]=1;
  1295.         LoopStart[ped_patsam][ped_split]=0;
  1296.         }
  1297.  
  1298.         draw_sampled_wave=true;
  1299.  
  1300.         if (userscreen==2){gui_action=107;teac=5;}
  1301.         }
  1302.                     
  1303.         if (zcheckMouse(516,476,29,16) && sed_range_mode){teac=20;gui_action=210;}
  1304.         if (zcheckMouse(516,512,60,16) && sed_range_mode){teac=21;gui_action=210;}
  1305.         if (zcheckMouse(516,494,60,16) && sed_range_mode){teac=22;gui_action=210;}
  1306.         if (zcheckMouse(516,530,60,16) && sed_range_mode){teac=23;gui_action=210;}
  1307.         if (zcheckMouse(516,548,60,16) && sed_range_mode){teac=24;gui_action=210;}
  1308.         if (zcheckMouse(547,476,29,16) && sed_range_mode){teac=25;gui_action=210;}
  1309.  
  1310.         if (zcheckMouse(578,512,60,16)){
  1311.         rs_coef=32768;
  1312.         sed_display_start=0;
  1313.         sed_display_length=SampleNumSamples[ped_patsam][ped_split];
  1314.         draw_sampled_wave=true;
  1315.         teac=3;
  1316.         gui_action=210;
  1317.         }
  1318.  
  1319.         if (zcheckMouse(578,530,60,16)){
  1320.         rs_coef/=2;
  1321.         draw_sampled_wave=true;
  1322.         }
  1323.  
  1324.         if (zcheckMouse(578,548,60,16)){
  1325.         rs_coef*=2;
  1326.         draw_sampled_wave=true;
  1327.         }
  1328.  
  1329.         if (zcheckMouse(578,494,60,16)){
  1330.         sed_range_mode=false;
  1331.         sed_range_start=0;
  1332.         sed_range_end=0;
  1333.         draw_sampled_wave=true;
  1334.         teac=0;
  1335.         gui_action=210;}
  1336.  
  1337.         if (zcheckMouse(578,476,60,16)){
  1338.         sed_range_mode=true;
  1339.         sed_range_start=sed_display_start;
  1340.         sed_range_end=sed_display_start+sed_display_length-1;
  1341.         draw_sampled_wave=true;
  1342.         teac=0;
  1343.         gui_action=210;}
  1344.         
  1345.         if (zcheckMouse(646,476,60,16) && sed_range_mode){
  1346.         sed_range_mode=false;
  1347.         sed_display_start=sed_range_start;
  1348.         sed_display_length=(sed_range_end-sed_range_start)+1;
  1349.         draw_sampled_wave=true;
  1350.         teac=3;
  1351.         gui_action=210;
  1352.         }
  1353.  
  1354.         if (zcheckMouse(646,494,60,16)){
  1355.         sed_display_start-=sed_display_length;
  1356.         if(sed_display_start<0)sed_display_start=0;
  1357.         sed_display_length*=3;
  1358.     
  1359.         if(sed_display_length+sed_display_start>SampleNumSamples[ped_patsam][ped_split])
  1360.         sed_display_length=SampleNumSamples[ped_patsam][ped_split]-sed_display_start;
  1361.  
  1362.         draw_sampled_wave=true;
  1363.         teac=3;
  1364.         gui_action=210;
  1365.         }
  1366.         }
  1367.         
  1368.         if (zcheckMouse(90,134,166,16) && snamesel==0){snamesel=2;sprintf(nameins[ped_patsam],"");namesize=0;gui_action=129;}
  1369.  
  1370.         if (zcheckMouse(394,42,16,14)){lt_index--;gui_action=100;}
  1371.         if (zcheckMouse(394,162,16,14)){lt_index++;gui_action=100;}
  1372.         if (zcheckMouse(412,43,220,133)){gui_action=2;}
  1373.         if (zcheckMouse(188,60,16,16) && cPosition>0){gui_action=3;}
  1374.         if (zcheckMouse(232,60,16,16) && cPosition<255){gui_action=4;}
  1375.         if (zcheckMouse(188,78,16,16) && pSequence[cPosition]>0){gui_action=7;}
  1376.         if (zcheckMouse(232,78,16,16) && pSequence[cPosition]<254){gui_action=8;}
  1377.         if (zcheckMouse(188,96,16,16) && sLength>1){gui_action=9;}
  1378.         if (zcheckMouse(232,96,16,16) && sLength<255){gui_action=10;}
  1379.         if (zcheckMouse(188,114,16,16) && patternLines[pSequence[cPosition]]>1){patternLines[pSequence[cPosition]]--;gui_action=5;}
  1380.         if (zcheckMouse(232,114,16,16) && patternLines[pSequence[cPosition]]<128){patternLines[pSequence[cPosition]]++;gui_action=5;}
  1381.         
  1382.         if (zcheckMouse(258,152,16,16)){gui_action=21;}
  1383.         if (zcheckMouse(302,152,16,16)){gui_action=22;}
  1384.         if (zcheckMouse(90,152,16,16)){gui_action=23;}
  1385.         if (zcheckMouse(134,152,16,16)){gui_action=24;}
  1386.         if (zcheckMouse(258,134,16,16)){gui_action=25;}
  1387.         if (zcheckMouse(302,134,16,16)){gui_action=26;}
  1388.         if (zcheckMouse(1,184,CONSOLE_WIDTH,124)){gui_action=27;}
  1389.         if (zcheckMouse(8,60,80,16)){plx=0;gui_action=28;}
  1390.         if (zcheckMouse(8,96,80,16)){gui_action=29;}
  1391.         if (zcheckMouse(8,78,80,16))
  1392.         {
  1393.             sr_isrecording++;
  1394.             if (sr_isrecording>1)sr_isrecording=0;
  1395.             gui_action=30;
  1396.         }
  1397.         
  1398.         if (zcheckMouse(320,134,64,16)){gui_action=201;}
  1399.         
  1400.         if (zcheckMouse(324,60,16,16) && Songtracks>1){Songtracks--;gui_action=40;teac=4;}
  1401.         if (zcheckMouse(368,60,16,16) && Songtracks<16){Songtracks++;gui_action=40;teac=4;}
  1402.         
  1403.         if (zcheckMouse(324,78,16,16)){BeatsPerMin--;gui_action=40;teac=1;}
  1404.         if (zcheckMouse(368,78,16,16)){BeatsPerMin++;gui_action=40;teac=1;}
  1405.         
  1406.         if (zcheckMouse(324,96,16,16)){TicksPerBeat--;gui_action=40;teac=2;}
  1407.         if (zcheckMouse(368,96,16,16)){TicksPerBeat++;gui_action=40;teac=2;}
  1408.  
  1409.         if (userscreen!=8)
  1410.         {
  1411.         if (zcheckMouse(376,309,64,16) && userscreen!=0)gui_action=60;
  1412.         if (zcheckMouse(442,309,64,16) && userscreen!=1)gui_action=61;
  1413.         if (zcheckMouse(508,309,64,16) && userscreen!=2){gui_action=62;seditor=0;}
  1414.         if (zcheckMouse(574,309,64,16) && userscreen!=3){gui_action=63;teac=0;}    
  1415.         if (zcheckMouse(310,309,64,16) && userscreen!=4)gui_action=64;    
  1416.         if (zcheckMouse(244,309,64,16) && userscreen!=5)gui_action=65;
  1417.         if (zcheckMouse(178,309,64,16) && userscreen!=6)gui_action=66;
  1418.         if (zcheckMouse(112,309,64,16) && userscreen!=7)gui_action=67;
  1419.         if (zcheckMouse(706,309,64,16) && userscreen!=9)gui_action=72;
  1420.         
  1421.         if (zcheckMouse(640,309,64,16))gui_action=68;
  1422.         }
  1423.         else if (zcheckMouse(640,434,64,16))gui_action=69;
  1424.         
  1425.         if (userscreen==7)
  1426.         {
  1427.         if (zcheckMouse(74,344,20,16) && LFO_ON[ped_track]==0){LFO_ON[ped_track]=1;gui_action=154;teac=9;}
  1428.         if (zcheckMouse(96,344,20,16) && LFO_ON[ped_track]==1){LFO_ON[ped_track]=0;gui_action=154;teac=9;}
  1429.         if (zcheckMouse(184,344,20,16) && FLANGER_ON[ped_track]==0){FLANGER_ON[ped_track]=1;gui_action=154;teac=10;}
  1430.         if (zcheckMouse(206,344,20,16) && FLANGER_ON[ped_track]==1){FLANGER_ON[ped_track]=0;gui_action=154;teac=10;}
  1431.         if (zcheckMouse(532,368,42,16) && Dispan[ped_track]){Dispan[ped_track]=false;gui_action=154;teac=11;}
  1432.         if (zcheckMouse(576,368,44,16) && !Dispan[ped_track]){Dispan[ped_track]=true;gui_action=154;teac=11;}
  1433.         }
  1434.  
  1435.     
  1436.         if (userscreen==4)
  1437.         {
  1438.         if (zcheckMouse(144,348,80,16)){SeqFill(0,256,false);gui_action=110;}
  1439.         if (zcheckMouse(144,366,80,16)){SeqFill(cPosition,cPosition+1,false);gui_action=110;}
  1440.         if (zcheckMouse(144,384,80,16)){SeqFill(0,256,true);gui_action=110;}
  1441.         if (zcheckMouse(144,402,80,16)){SeqFill(cPosition,cPosition+1,true);gui_action=110;}
  1442.         if (zcheckMouse(178,420,22,16)){Scopish=true;gui_action=205;}
  1443.         if (zcheckMouse(202,420,22,16)){Scopish=false;gui_action=205;}
  1444.         
  1445.         if (zcheckMouse(410,348,80,16))
  1446.         {
  1447.         if(cPosition<128){pSequence[cPosition]=cPosition;Anat(cPosition);gui_action=110;}
  1448.         }
  1449.         
  1450.         if (zcheckMouse(410,364,80,16))
  1451.         {
  1452.         for(int xpos=0;xpos<128;xpos++)pSequence[xpos]=xpos;
  1453.  
  1454.         gui_action=110;
  1455.         }
  1456.         
  1457.         if (zcheckMouse(399,345,8,84))
  1458.         {
  1459.         int posindex=((LastY-348)/12)-3;
  1460.         posindex+=cPosition;
  1461.  
  1462.         if (pSequence[posindex]<127)
  1463.             {
  1464.                 pSequence[posindex]++;
  1465.                 Anat(posindex);
  1466.  
  1467.                 if (posindex!=cPosition)
  1468.                     gui_action=110;
  1469.                 else
  1470.                     gui_action=111;
  1471.             
  1472.             }
  1473.             else
  1474.                     gui_action=204;
  1475.         }
  1476.  
  1477.         if (zcheckMouse(392,345,8,84))
  1478.         {
  1479.         int posindex=((LastY-348)/12)-3;
  1480.         posindex+=cPosition;
  1481.  
  1482.         if (pSequence[posindex]<127)
  1483.             {
  1484.                 pSequence[posindex]+=10;    
  1485.                 if(pSequence[posindex]>=128)
  1486.                 pSequence[posindex]=127;
  1487.                 Anat(posindex);
  1488.  
  1489.                 if (posindex!=cPosition)
  1490.                     gui_action=110;
  1491.                 else
  1492.                     gui_action=111;
  1493.             }
  1494.             else
  1495.             gui_action=204;
  1496.             
  1497.         }
  1498.         
  1499.         if (zcheckMouse(256,346,130,84)==1){
  1500.             int posindex=((LastY-348)/12)-3;
  1501.             posindex+=cPosition;
  1502.         
  1503.             if (posindex>-1 && posindex<256){
  1504.             int seqindex=(LastX-258)/8;
  1505.             if (seqindex<0)seqindex=0;
  1506.             if (seqindex>MAX_TRACKS-1)seqindex=MAX_TRACKS-1;
  1507.             
  1508.             if (!SACTIVE[posindex][seqindex])
  1509.             SACTIVE[posindex][seqindex]=true;
  1510.             else
  1511.             SACTIVE[posindex][seqindex]=false;
  1512.             gui_action=110;}}
  1513.  
  1514.             if (zcheckMouse(232,346,16,84)){
  1515.             int posindex=((LastY-348)/12)-3;
  1516.             posindex+=cPosition;
  1517.             if (posindex>-1 && posindex<256 && posindex!=cPosition)
  1518.             {cPosition=posindex;gui_action=111;}}
  1519.  
  1520.         }
  1521.         
  1522.         if (userscreen==0)
  1523.         {
  1524.         if (zcheckMouse(8,368,80,16)){gui_action=102;}
  1525.         if (zcheckMouse(172,350,80,16)){gui_action=70;}
  1526.         if (zcheckMouse(172,368,80,16)){gui_action=71;}
  1527.         if (zcheckMouse(8,350,80,16)){gui_action=103;}
  1528.         if (zcheckMouse(90,386,162,16) && snamesel==0){sprintf(name,"");namesize=0;snamesel=1;gui_action=108;}
  1529.         if (zcheckMouse(90,404,162,16) && snamesel==0){sprintf(artist,"");namesize=0;snamesel=4;gui_action=108;}
  1530.         if (zcheckMouse(90,422,162,16) && snamesel==0){sprintf(style,"");namesize=0;snamesel=5;gui_action=108;}
  1531.         
  1532.         if (zcheckMouse(264,368,64,16) && QUALITYPLAY!=0){QUALITYPLAY=0;gui_action=108;QUALITYCHANGE=true;}
  1533.         if (zcheckMouse(264,386,64,16) && QUALITYPLAY!=1){QUALITYPLAY=1;gui_action=108;QUALITYCHANGE=true;}
  1534.         if (zcheckMouse(264,404,64,16) && QUALITYPLAY!=2){QUALITYPLAY=2;gui_action=108;QUALITYCHANGE=true;}
  1535.  
  1536.         if (zcheckMouse(90,350,80,16)){gui_action=109;}
  1537.         if (zcheckMouse(482,350,16,16) && XLATENCY_TIME>10){XLATENCY_TIME-=10;if (XLATENCY_TIME<10)XLATENCY_TIME=10;Resetdevice();gui_action=108;}
  1538.         if (zcheckMouse(526,350,16,16) && XLATENCY_TIME<250){XLATENCY_TIME+=10;if (XLATENCY_TIME>250)XLATENCY_TIME=250;Resetdevice();gui_action=108;}
  1539.         if (zcheckMouse(90,368,80,16)){rawrender=true;gui_action=169;}
  1540.         }
  1541.  
  1542.         if (userscreen==1)
  1543.         {
  1544.         if (zcheckMouse(77,396,16,16) && FType[ped_track]>0){ResetFilters(ped_track);FType[ped_track]--;teac=4;gui_action=53;}
  1545.         if (zcheckMouse(121,396,16,16) && FType[ped_track]<MAX_FILTER){ResetFilters(ped_track);FType[ped_track]++;teac=4;gui_action=53;}
  1546.         if (zcheckMouse(508,362,16,16)){ped_track--;teac=0;gui_action=53;trkchan=true;}
  1547.         if (zcheckMouse(552,362,16,16)){ped_track++;teac=0;gui_action=53;trkchan=true;}    
  1548.         if (zcheckMouse(570,362,16,16)){CSend[ped_track]--;teac=6;gui_action=53;}
  1549.         if (zcheckMouse(614,362,16,16)){CSend[ped_track]++;teac=6;gui_action=53;}    
  1550.  
  1551.         if (zcheckMouse(456,360,40,16)){DThreshold[ped_track]=DClamp[ped_track];teac=7;gui_action=53;}    
  1552.         if (zcheckMouse(456,378,40,16)){DClamp[ped_track]=DThreshold[ped_track];teac=8;gui_action=53;}    
  1553.         if (zcheckMouse(456,414,40,16)){TPan[ped_track]=0.5f;gui_action=53;teac=9;}    
  1554.  
  1555.         if (zcheckMouse(570,406,16,16)){TRACKMIDICHANNEL[ped_track]--;gui_action=53;teac=11;}    
  1556.         if (zcheckMouse(614,406,16,16)){TRACKMIDICHANNEL[ped_track]++;gui_action=53;teac=11;}    
  1557.  
  1558.         // Mute track
  1559.         
  1560.         if (zcheckMouse(570,424,60,16)){Disclap[ped_track]=!Disclap[ped_track];gui_action=53;teac=12;}
  1561.  
  1562.         if (zcheckMouse(508,388,64,16)){
  1563.             if(TRACKSTATE[ped_track]==0)
  1564.             TRACKSTATE[ped_track]=1;
  1565.             else
  1566.             TRACKSTATE[ped_track]=0;gui_action=53;teac=10;trkchan=true;}    
  1567.         
  1568.         // Solo track
  1569.  
  1570.         if (zcheckMouse(508,406,64,16)){for (int solify=0;solify<MAX_TRACKS;solify++){TRACKSTATE[solify]=1;}TRACKSTATE[ped_track]=0;gui_action=53;trkchan=true;teac=10;}    
  1571.         
  1572.         // Unmute all tracks
  1573.  
  1574.         if (zcheckMouse(508,424,88,16)){for (int solify=0;solify<MAX_TRACKS;solify++){TRACKSTATE[solify]=0;}gui_action=53;trkchan=true;teac=10;}    
  1575.         
  1576.         }// Userscreen 1
  1577.  
  1578.         if (userscreen==2 && seditor==1){
  1579.         if (zcheckMouse(96,350,16,16) && LoopStart[ped_patsam][ped_split]>0){LoopStart[ped_patsam][ped_split]--;gui_action=107;teac=5;}
  1580.         if (zcheckMouse(176,350,16,16) && LoopStart[ped_patsam][ped_split]<LoopEnd[ped_patsam][ped_split]){LoopStart[ped_patsam][ped_split]++;gui_action=107;teac=5;}
  1581.         if (zcheckMouse(296,350,16,16) && LoopEnd[ped_patsam][ped_split]>LoopStart[ped_patsam][ped_split]){LoopEnd[ped_patsam][ped_split]--;gui_action=101;teac=5;}
  1582.         if (zcheckMouse(376,350,16,16) && LoopEnd[ped_patsam][ped_split]<SampleNumSamples[ped_patsam][ped_split]-1){LoopEnd[ped_patsam][ped_split]++;gui_action=101;teac=5;}    
  1583.         if (zcheckMouse(424,391,64,16)){seditor=0;gui_action=62;}
  1584.         }
  1585.  
  1586.         if (userscreen==2 && seditor==0){
  1587.         if (zcheckMouse(570,373,16,16) && Midiprg[ped_patsam]>-1){Midiprg[ped_patsam]--;gui_action=107;teac=10;}
  1588.         if (zcheckMouse(614,373,16,16) && Midiprg[ped_patsam]<127){Midiprg[ped_patsam]++;gui_action=107;teac=10;}
  1589.         if (zcheckMouse(570,391,28,16)){Synthprg[ped_patsam]=false;gui_action=107;teac=11;}
  1590.         if (zcheckMouse(602,391,28,16)){Synthprg[ped_patsam]=true;gui_action=107;teac=11;}
  1591.         
  1592.         if (zcheckMouse(144,372,28,16)){beatsync[ped_patsam]=false;gui_action=107;teac=12;}
  1593.         if (zcheckMouse(174,372,28,16)){beatsync[ped_patsam]=true;gui_action=107;teac=12;}
  1594.         
  1595.         if (zcheckMouse(144,390,16,16) && beatlines[ped_patsam]>1){beatlines[ped_patsam]--;gui_action=107;teac=13;}
  1596.         if (zcheckMouse(188,390,16,16) && beatlines[ped_patsam]<128){beatlines[ped_patsam]++;gui_action=107;teac=13;}
  1597.         
  1598.         if (zcheckMouse(570,337,16,16) && ped_split>0){ped_split--;gui_action=101;teac=0;NewWavy();}
  1599.         if (zcheckMouse(614,337,16,16) && ped_split<15){ped_split++;gui_action=101;teac=0;NewWavy();}
  1600.         if (zcheckMouse(268,346,88,16) && SampleType[ped_patsam][ped_split]){seditor=1;gui_action=62;}
  1601.         if (zcheckMouse(268,364,88,16) && SampleType[ped_patsam][ped_split]){gui_action=107;teac=14;}
  1602.         
  1603.         if (zcheckMouse(570,355,16,16) && Basenote[ped_patsam][ped_split]>0){Basenote[ped_patsam][ped_split]--;teac=9;gui_action=107;}
  1604.         if (zcheckMouse(614,355,16,16) && Basenote[ped_patsam][ped_split]<119){Basenote[ped_patsam][ped_split]++;teac=9;gui_action=107;}
  1605.         
  1606.         if (SampleType[ped_patsam][ped_split]!=0)
  1607.         {
  1608.         if (zcheckMouse(448,391,29,16)){LoopType[ped_patsam][ped_split]=1;teac=5;gui_action=107;draw_sampled_wave=true;}
  1609.         if (zcheckMouse(478,391,29,16)){LoopType[ped_patsam][ped_split]=0;teac=5;gui_action=107;draw_sampled_wave=true;}
  1610.         if (zcheckMouse(268,418,88,16)){} /* Range Loop Buttoon */
  1611.         if (zcheckMouse(268,400,88,16)){} /* Smooth Loop Buttoon */
  1612.         }
  1613.     
  1614.         }
  1615.  
  1616.         if (userscreen==3)
  1617.         {
  1618.         if (zcheckMouse(77,396,16,16)==1){DelayType--;gui_action=112;teac=1;}
  1619.         if (zcheckMouse(121,396,32,16)==1){DelayType++;gui_action=112;teac=1;}
  1620.         
  1621.         if (zcheckMouse(540,360,16,16)==1){lchorus_delay=SamplesPerTick;gui_action=112;teac=3;}
  1622.         if (zcheckMouse(540,378,16,16)==1){rchorus_delay=SamplesPerTick;gui_action=112;teac=4;}
  1623.         
  1624.         if (zcheckMouse(558,360,16,16)==1){lchorus_delay=SamplesPerTick*2;gui_action=112;teac=3;}
  1625.         if (zcheckMouse(558,378,16,16)==1){rchorus_delay=SamplesPerTick*2;gui_action=112;teac=4;}
  1626.         
  1627.         if (zcheckMouse(576,360,16,16)==1){lchorus_delay=SamplesPerTick*3;gui_action=112;teac=3;}
  1628.         if (zcheckMouse(576,378,16,16)==1){rchorus_delay=SamplesPerTick*3;gui_action=112;teac=4;}
  1629.         
  1630.         if (zcheckMouse(594,360,16,16)==1){lchorus_delay=SamplesPerTick*4;gui_action=112;teac=3;}
  1631.         if (zcheckMouse(594,378,16,16)==1){rchorus_delay=SamplesPerTick*4;gui_action=112;teac=4;}
  1632.         
  1633.         if (zcheckMouse(612,360,16,16)==1){lchorus_delay=SamplesPerTick*5;gui_action=112;teac=3;}
  1634.         if (zcheckMouse(612,378,16,16)==1){rchorus_delay=SamplesPerTick*5;gui_action=112;teac=4;}
  1635.  
  1636.         if (compressor==0 && zcheckMouse(78,360,32,16)==1){compressor=1;gui_action=112;teac=8;}
  1637.         if (compressor==1 && zcheckMouse(112,360,32,16)==1){compressor=0;gui_action=112;teac=8;}    
  1638.         }
  1639.  
  1640.         if (userscreen==6)
  1641.         {
  1642.         if (zcheckMouse(598,352,34,16)){gui_action=202;}
  1643.         if (zcheckMouse(598,370,34,16)){gui_action=206;}
  1644.  
  1645.         if (zcheckMouse(432,352,128,16) && snamesel==0){snamesel=3;namesize=0;sprintf(PARASynth[ped_patsam].presetname,"");teac=10;gui_action=150;}
  1646.         if (zcheckMouse(66,352,16,16)){c_midiin--;gui_action=150;midiin_changed=true;teac=8;}
  1647.         if (zcheckMouse(110,352,16,16)){c_midiin++;gui_action=150;midiin_changed=true;teac=8;}
  1648.         
  1649.         if (zcheckMouse(66,370,16,16)==1){c_midiout--;gui_action=150;midiout_changed=true;teac=9;}
  1650.         if (zcheckMouse(110,370,16,16)==1){c_midiout++;gui_action=150;midiout_changed=true;teac=9;}
  1651.         if (zcheckMouse(406,370,16,16) && ped_synthpar>1){ped_synthpar--;gui_action=150;teac=2;}
  1652.         if (zcheckMouse(450,370,16,16) && ped_synthpar<51){ped_synthpar++;gui_action=150;teac=2;}    
  1653.         if (zcheckMouse(388,406,24,16)){PARASynth[ped_patsam].osc1_waveform=0;teac=3;gui_action=150;}
  1654.         if (zcheckMouse(414,406,24,16)){PARASynth[ped_patsam].osc1_waveform=1;teac=3;gui_action=150;}
  1655.         if (zcheckMouse(440,406,24,16)){PARASynth[ped_patsam].osc1_waveform=2;teac=3;gui_action=150;}
  1656.         if (zcheckMouse(466,406,24,16)){PARASynth[ped_patsam].osc1_waveform=3;teac=3;gui_action=150;}
  1657.         if (zcheckMouse(492,406,24,16)){PARASynth[ped_patsam].osc1_waveform=4;teac=3;gui_action=150;}
  1658.         if (zcheckMouse(388,424,24,16)){PARASynth[ped_patsam].osc2_waveform=0;teac=4;gui_action=150;}
  1659.         if (zcheckMouse(414,424,24,16)){PARASynth[ped_patsam].osc2_waveform=1;teac=4;gui_action=150;}
  1660.         if (zcheckMouse(440,424,24,16)){PARASynth[ped_patsam].osc2_waveform=2;teac=4;gui_action=150;}
  1661.         if (zcheckMouse(466,424,24,16)){PARASynth[ped_patsam].osc2_waveform=3;teac=4;gui_action=150;}
  1662.         if (zcheckMouse(492,424,24,16)){PARASynth[ped_patsam].osc2_waveform=4;teac=4;gui_action=150;}
  1663.         if (zcheckMouse(572,406,24,16)){PARASynth[ped_patsam].osc3_switch=true;teac=5;gui_action=150;}
  1664.         if (zcheckMouse(596,406,24,16)){PARASynth[ped_patsam].osc3_switch=false;teac=5;gui_action=150;}
  1665.         if (zcheckMouse(572,424,24,16) && PARASynth[ped_patsam].vcf_type>0){PARASynth[ped_patsam].vcf_type--;teac=7;gui_action=150;}
  1666.         if (zcheckMouse(616,424,24,16) && PARASynth[ped_patsam].vcf_type<2){PARASynth[ped_patsam].vcf_type++;teac=7;gui_action=150;}
  1667.                 
  1668.         if (zcheckMouse(8,388,124,16)==1 && c_midiout!=-1)
  1669.         {
  1670.         midiOutShortMsg(midiout_handle, (176+TRACKMIDICHANNEL[ped_track]) | (123 << 8) | (0 << 16)); 
  1671.         gui_action=151;
  1672.         }
  1673.  
  1674.         if (zcheckMouse(134,388,124,16)==1  && c_midiout!=-1)
  1675.         {
  1676.         MidiAllNotesOff();
  1677.         gui_action=152;
  1678.         }
  1679.  
  1680.         if (zcheckMouse(8,406,80,16)==1){;}
  1681.         
  1682.         }
  1683.     }//rc depressing
  1684. }// leftbutton
  1685. else
  1686. {gui_pushed=0;sas=false;}
  1687.  
  1688. if (C->getMouse()->rightButton() && rc==3)
  1689. {
  1690.     gui_action=255;
  1691.  
  1692.     if (zcheckMouse(90,152,16,16)){ped_pattad=1;gui_action=129;}
  1693.     if (zcheckMouse(134,152,16,16)){ped_pattad=16;gui_action=129;}
  1694.  
  1695.     if (zcheckMouse(188,114,16,16)){
  1696.         int ltp=patternLines[pSequence[cPosition]];
  1697.         ltp-=16;
  1698.         if(ltp<1)ltp=1;
  1699.     patternLines[pSequence[cPosition]]=ltp;
  1700.     gui_action=5;}
  1701.     
  1702.     if (zcheckMouse(232,114,16,16)){
  1703.         int ltp=patternLines[pSequence[cPosition]];
  1704.         ltp+=16;
  1705.         if(ltp>128)ltp=128;
  1706.     patternLines[pSequence[cPosition]]=ltp;
  1707.     gui_action=5;}
  1708.     
  1709.     if (zcheckMouse(258,134,16,16)==1){gui_action=125;}
  1710.     if (zcheckMouse(302,134,16,16)==1){gui_action=126;}
  1711.     
  1712.     if (zcheckMouse(8,60,80,16)==1){plx=1;gui_action=28;}
  1713.     if (zcheckMouse(394,42,16,14)==1){lt_index-=10;gui_action=100;}
  1714.     if (zcheckMouse(394,162,16,14)==1){lt_index+=10;gui_action=100;}
  1715.     if (zcheckMouse(188,60,16,16)==1 && cPosition!=0){int tposition=cPosition;tposition-=10;if(tposition<0)tposition=0;cPosition=tposition;gui_action=5;}
  1716.     if (zcheckMouse(232,60,16,16)==1 && cPosition!=255){int tposition=cPosition;tposition+=10;if(tposition>255)tposition=255;cPosition=tposition;gui_action=5;}
  1717.  
  1718.     if (zcheckMouse(188,96,16,16)==1 && sLength!=1){int tLength=sLength;tLength-=10;if (tLength<1)tLength=1;sLength=tLength;gui_action=11;}
  1719.     if (zcheckMouse(232,96,16,16)==1 && sLength!=255){int tLength=sLength;tLength+=10;if (tLength>255)tLength=255;sLength=tLength;gui_action=11;}
  1720.  
  1721.     if (zcheckMouse(188,78,16,16)==1){gui_action=115;}
  1722.     if (zcheckMouse(232,78,16,16)==1){gui_action=116;}
  1723.  
  1724.     guiDial(106,384,32,16,"On",200);
  1725.     guiDial(140,384,32,16,"Off",100);
  1726.  
  1727.     
  1728.     if (userscreen==1)
  1729.     {
  1730.     if (zcheckMouse(570,362,16,16)==1){CSend[ped_track]-=16;gui_action=53;}
  1731.     if (zcheckMouse(614,362,16,16)==1){CSend[ped_track]+=16;gui_action=53;}    
  1732.     }
  1733.  
  1734.     if (userscreen==2 && seditor==0)
  1735.     {
  1736.     if (zcheckMouse(144,391,16,16) && beatlines[ped_patsam]>1)
  1737.     {
  1738.         beatlines[ped_patsam]-=16;
  1739.         if(beatlines[ped_patsam]<1)beatlines[ped_patsam]=1;
  1740.         gui_action=107;
  1741.         teac=13;
  1742.     }
  1743.  
  1744.     if (zcheckMouse(188,391,16,16) && beatlines[ped_patsam]<128)
  1745.     {
  1746.         beatlines[ped_patsam]+=16;
  1747.         if(beatlines[ped_patsam]>128)beatlines[ped_patsam]=128;
  1748.         gui_action=107;
  1749.         teac=13;}
  1750.         
  1751.     if (zcheckMouse(570,373,16,16) && Midiprg[ped_patsam]>-1)
  1752.     {    if(Midiprg[ped_patsam]>14)
  1753.         Midiprg[ped_patsam]-=16;
  1754.         else
  1755.         Midiprg[ped_patsam]=-1;
  1756.         gui_action=107;
  1757.     teac=10;}
  1758.     
  1759.     if (zcheckMouse(614,373,16,16) && Midiprg[ped_patsam]<127)
  1760.     {
  1761.         if(Midiprg[ped_patsam]<111)
  1762.         Midiprg[ped_patsam]+=16;
  1763.         else
  1764.         Midiprg[ped_patsam]=127;
  1765.         gui_action=107;
  1766.     teac=10;}    
  1767.  
  1768.     if (zcheckMouse(570,355,16,16) && Basenote[ped_patsam][ped_split]>0)
  1769.     {    if(Basenote[ped_patsam][ped_split]>11)
  1770.         Basenote[ped_patsam][ped_split]-=12;
  1771.         else
  1772.         Basenote[ped_patsam][ped_split]=0;
  1773.         gui_action=107;
  1774.     teac=9;}
  1775.     
  1776.     if (zcheckMouse(614,355,16,16) && Basenote[ped_patsam][ped_split]<119)
  1777.     {
  1778.         if(Basenote[ped_patsam][ped_split]<107)
  1779.         Basenote[ped_patsam][ped_split]+=12;
  1780.         else
  1781.         Basenote[ped_patsam][ped_split]=119;
  1782.         gui_action=107;
  1783.     teac=9;}
  1784.     }
  1785.  
  1786.     if (userscreen==4)
  1787.         {
  1788.  
  1789.         if (zcheckMouse(399,345,8,84))
  1790.         {
  1791.         int posindex=((LastY-348)/12)-3;
  1792.         posindex+=cPosition;
  1793.  
  1794.         if (pSequence[posindex]>0)
  1795.             {
  1796.                 pSequence[posindex]--;
  1797.                 Anat(posindex);
  1798.  
  1799.                 if (posindex!=cPosition)
  1800.                     gui_action=110;
  1801.                 else
  1802.                     gui_action=111;
  1803.             }
  1804.         }
  1805.  
  1806.         if (zcheckMouse(392,345,8,84))
  1807.         {
  1808.         int posindex=((LastY-348)/12)-3;
  1809.         posindex+=cPosition;
  1810.  
  1811.         if (pSequence[posindex]>0)
  1812.             {
  1813.                 int reak=pSequence[posindex];
  1814.                 
  1815.                 reak-=10;
  1816.                 if (reak<0)reak=0;
  1817.                 pSequence[posindex]=reak;
  1818.                 Anat(posindex);
  1819.  
  1820.                 if (posindex!=cPosition)
  1821.                     gui_action=110;
  1822.                 else
  1823.                     gui_action=111;
  1824.             }            
  1825.         }
  1826.  
  1827.         if (zcheckMouse(256,346,130,84)==1){
  1828.             int posindex=((LastY-348)/12)-3;
  1829.             posindex+=cPosition;
  1830.             
  1831.             if (posindex>-1 && posindex<256){
  1832.             int seqindex=(LastX-258)/8;
  1833.             if (seqindex<0)seqindex=0;
  1834.             if (seqindex>Songtracks-1)seqindex=Songtracks-1;
  1835.             
  1836.             if (SACTIVE[posindex][seqindex])
  1837.             {
  1838.             for (int alphac=0;alphac<Songtracks;alphac++)
  1839.             SACTIVE[posindex][alphac]=false;
  1840.             }
  1841.  
  1842.             SACTIVE[posindex][seqindex]=true;
  1843.             gui_action=110;}}// action 110
  1844.         }//userscr4
  1845.     
  1846.     if (userscreen==6)
  1847.     {
  1848.     if (zcheckMouse(406,370,16,16) && ped_synthpar>1){ped_synthpar-=10;gui_action=150;teac=2;}
  1849.     if (zcheckMouse(450,370,16,16) && ped_synthpar<51){ped_synthpar+=10;gui_action=150;teac=2;}
  1850.     }
  1851. } // RIGHT MOUSE
  1852.  
  1853. }// Mouse event true
  1854.       
  1855. // KeyBoard ShortCut Handler ------------------------------------
  1856.  
  1857.  Keyboard& K=*C->getKeyboard();
  1858.  K.update();
  1859.  
  1860.   if (K[DIK_ESCAPE] && K[DIK_LMENU]){gui_action=254;}
  1861.   if (K[DIK_F5] && !K[DIK_LSHIFT] && !K[DIK_LCONTROL] && ped_line!=0){vloid();ped_line=0;Actupated(0);}
  1862.   if (K[DIK_F6] && ped_line!=16){ped_line=16;Actupated(0);}
  1863.   if (K[DIK_F7] && ped_line!=32){ped_line=32;Actupated(0);}
  1864.   if (K[DIK_F8] && ped_line!=48){ped_line=48;Actupated(0);}
  1865.   if (K[DIK_F9] && ped_line!=63){ped_line=63;Actupated(0);}
  1866.   
  1867.   if (poslad==false && !K[DIK_SUBTRACT] && !K[DIK_ADD] && !K[DIK_MULTIPLY] && !K[DIK_DIVIDE] && !K[DIK_NEXT] && !K[DIK_PRIOR] && !K[DIK_UP] && !K[DIK_DOWN] && !K[DIK_TAB] && !K[DIK_RIGHT] && !K[DIK_LEFT]){poslad=true;}
  1868.   
  1869.   if (K[DIK_RIGHT] && poslad==true){poslad=false;ped_row++;Actupated(1);}
  1870.   if (K[DIK_LEFT] && poslad==true){poslad=false;ped_row--;Actupated(1);}
  1871.   if (!K[DIK_LSHIFT] && K[DIK_TAB] && poslad==true){ped_track++;ped_row=0;Actupated(1);poslad=false;gui_action=15;}
  1872.   if (K[DIK_LSHIFT] && K[DIK_TAB] && poslad==true){ped_track--;ped_row=0;Actupated(1);poslad=false;gui_action=16;}
  1873.   if (K[DIK_UP] && poslad==true){ped_line--;Actupated(0);poslad=false;}
  1874.   if (K[DIK_DOWN] && poslad==true){ped_line++;Actupated(0);poslad=false;}
  1875.   if (K[DIK_PRIOR] && poslad==true){;ped_line-=16;if (ped_line<0)ped_line=0;Actupated(0);poslad=false;}
  1876.   if (K[DIK_NEXT] && poslad==true && ped_line<patternLines[pSequence[cPosition]]){ped_line+=16;if (ped_line>=patternLines[pSequence[cPosition]])ped_line=patternLines[pSequence[cPosition]]-1;Actupated(0);poslad=false;}
  1877.   
  1878.   if (K[DIK_DIVIDE] && poslad==true){vloid();gui_action=21;poslad=false;}
  1879.   if (K[DIK_MULTIPLY] && poslad==true){vloid();gui_action=22;poslad=false;}
  1880.  
  1881.   if (K[DIK_SUBTRACT] && poslad==true && pSequence[cPosition]>0){vloid();gui_action=7;poslad=false;}
  1882.   if (K[DIK_ADD] && poslad==true && pSequence[cPosition]<254){vloid();gui_action=8;poslad=false;}
  1883.     
  1884. int retnote=120; // NO NOTE
  1885. int retvalue=120; // NOVALUE
  1886. retletter=0;
  1887.  
  1888. if (snamesel>0)
  1889. {
  1890. if (K[DIK_A])retletter=1;
  1891. if (K[DIK_B])retletter=2;
  1892. if (K[DIK_C])retletter=3;
  1893. if (K[DIK_D])retletter=4;
  1894. if (K[DIK_E])retletter=5;
  1895. if (K[DIK_F])retletter=6;
  1896. if (K[DIK_G])retletter=7;
  1897. if (K[DIK_H])retletter=8;
  1898. if (K[DIK_I])retletter=9;
  1899. if (K[DIK_J])retletter=10;
  1900. if (K[DIK_K])retletter=11;
  1901. if (K[DIK_L])retletter=12;
  1902. if (K[DIK_M])retletter=13;
  1903. if (K[DIK_N])retletter=14;
  1904. if (K[DIK_O])retletter=15;
  1905. if (K[DIK_P])retletter=16;
  1906. if (K[DIK_Q])retletter=17;
  1907. if (K[DIK_R])retletter=18;
  1908. if (K[DIK_S])retletter=19;
  1909. if (K[DIK_T])retletter=20;
  1910. if (K[DIK_U])retletter=21;
  1911. if (K[DIK_V])retletter=22;
  1912. if (K[DIK_W])retletter=23;
  1913. if (K[DIK_X])retletter=24;
  1914. if (K[DIK_Y])retletter=25;
  1915. if (K[DIK_Z])retletter=26;
  1916. if (K[DIK_0])retletter=27;
  1917. if (K[DIK_1])retletter=28;
  1918. if (K[DIK_2])retletter=29;
  1919. if (K[DIK_3])retletter=30;
  1920. if (K[DIK_4])retletter=31;
  1921. if (K[DIK_5])retletter=32;
  1922. if (K[DIK_6])retletter=33;
  1923. if (K[DIK_7])retletter=34;
  1924. if (K[DIK_8])retletter=35;
  1925. if (K[DIK_9])retletter=36;
  1926. if (K[DIK_BACK])retletter=37;
  1927. if (K[DIK_SPACE])retletter=38;
  1928. if (K[DIK_RETURN])retletter=39;
  1929. if (K[DIK_PERIOD])retletter=40;
  1930. if (K[DIK_COMMA])retletter=67;
  1931. if (K[DIK_SLASH])retletter=68;
  1932. if (K[DIK_MINUS])retletter=69;
  1933. if (K[DIK_EQUALS])retletter=70;
  1934. }
  1935.  
  1936. if ((K[DIK_LSHIFT] || K[DIK_RSHIFT])&& retletter<27 && retletter>0)
  1937. tretletter=retletter+40;
  1938. else
  1939. tretletter=retletter;
  1940.  
  1941. if (retletter==0)posletter=0;
  1942. if (retletter!=0 && posletter!=retletter)
  1943. {
  1944.     vloid();
  1945.     switch (snamesel)
  1946.     {
  1947.     case 1:
  1948.         Actualize_Songname(tretletter,name);
  1949.         gui_action=108;
  1950.     break;
  1951.  
  1952.     case 2:
  1953.         Actualize_Songname(tretletter,nameins[ped_patsam]);
  1954.         gui_action=129;
  1955.     break;
  1956.     
  1957.     case 3:
  1958.         Actualize_Songname(tretletter,PARASynth[ped_patsam].presetname);
  1959.         teac=10;
  1960.         gui_action=150;
  1961.     break;
  1962.  
  1963.     case 4:
  1964.         Actualize_Songname(tretletter,artist);
  1965.         gui_action=108;
  1966.     break;
  1967.  
  1968.     case 5:
  1969.         Actualize_Songname(tretletter,style);
  1970.         gui_action=108;
  1971.     break;
  1972.  
  1973.     }
  1974.  
  1975.     posletter=retletter;
  1976. }
  1977.  
  1978. if (!K[DIK_LMENU] && !K[DIK_LCONTROL] && po_ctrl==1 && snamesel==0)
  1979. {
  1980. if (K[DIK_Z])retnote=0;
  1981. if (K[DIK_S])retnote=1;
  1982. if (K[DIK_X])retnote=2;
  1983. if (K[DIK_D])retnote=3;
  1984. if (K[DIK_C])retnote=4;
  1985. if (K[DIK_V])retnote=5;
  1986. if (K[DIK_G])retnote=6;
  1987. if (K[DIK_B])retnote=7;
  1988. if (K[DIK_H])retnote=8;
  1989. if (K[DIK_N])retnote=9;
  1990. if (K[DIK_J])retnote=10;
  1991. if (K[DIK_M])retnote=11;
  1992. if (K[DIK_COMMA])retnote=12;
  1993. if (K[DIK_L])retnote=13;
  1994. if (K[DIK_PERIOD])retnote=14;
  1995. if (K[DIK_SEMICOLON])retnote=15;
  1996. if (K[DIK_SLASH])retnote=16;
  1997. if (K[DIK_Q])retnote=12;
  1998. if (K[DIK_2])retnote=13;
  1999. if (K[DIK_W])retnote=14;
  2000. if (K[DIK_3])retnote=15;
  2001. if (K[DIK_E])retnote=16;
  2002. if (K[DIK_R])retnote=17;
  2003. if (K[DIK_5])retnote=18;
  2004. if (K[DIK_T])retnote=19;
  2005. if (K[DIK_6])retnote=20;
  2006. if (K[DIK_Y])retnote=21;
  2007. if (K[DIK_7])retnote=22;
  2008. if (K[DIK_U])retnote=23;
  2009. if (K[DIK_I])retnote=24;
  2010. if (K[DIK_9])retnote=25;
  2011. if (K[DIK_O])retnote=26;
  2012. if (K[DIK_0])retnote=27;
  2013. if (K[DIK_P])retnote=28;
  2014. if (K[DIK_DELETE])retnote=-1;
  2015. if (K[DIK_INSERT])retnote=-2;
  2016. if (K[DIK_RSHIFT])retnote=-3;
  2017. if (K[DIK_BACKSPACE])retnote=-4;
  2018. if (K[DIK_0])retvalue=0;
  2019. if (K[DIK_1])retvalue=1;
  2020. if (K[DIK_2])retvalue=2;
  2021. if (K[DIK_3])retvalue=3;
  2022. if (K[DIK_4])retvalue=4;
  2023. if (K[DIK_5])retvalue=5;
  2024. if (K[DIK_6])retvalue=6;
  2025. if (K[DIK_7])retvalue=7;
  2026. if (K[DIK_8])retvalue=8;
  2027. if (K[DIK_9])retvalue=9;
  2028. if (K[DIK_A])retvalue=10;
  2029. if (K[DIK_B])retvalue=11;
  2030. if (K[DIK_C])retvalue=12;
  2031. if (K[DIK_D])retvalue=13;
  2032. if (K[DIK_E])retvalue=14;
  2033. if (K[DIK_F])retvalue=15;
  2034. if (K[DIK_DELETE])retvalue=16;
  2035. }
  2036.  
  2037. if (K[DIK_SPACE] && snamesel==0 && pos_space==1)
  2038. {
  2039. vloid();
  2040. gui_action=29;
  2041. if (Songplaying==0)is_editing++;
  2042. pos_space=0;
  2043. }
  2044.  
  2045. if (pos_space==0 && !K[DIK_SPACE])pos_space=1;
  2046.  
  2047. if (K[DIK_RCONTROL] && snamesel==0 && po_ctrl2){vloid();plx=0;po_ctrl2=false;gui_action=28;}
  2048. if (!K[DIK_RCONTROL] && !po_ctrl2)po_ctrl2=true;
  2049.  
  2050. if (!K[DIK_F1] && !K[DIK_F2] && !K[DIK_F3] && !K[DIK_F4] && !K[DIK_F5] && po_shift==0)po_shift=1;
  2051. if (!K[DIK_F5] && !K[DIK_F4] && !K[DIK_F3] && !K[DIK_C] && !K[DIK_X] && !K[DIK_V] && !K[DIK_B] && !K[DIK_E] && !K[DIK_Z] && !K[DIK_I] && !K[DIK_R] && !K[DIK_S] && po_ctrl==0)po_ctrl=1;
  2052.  
  2053. if (K[DIK_LCONTROL] && po_ctrl==1)
  2054. {
  2055.     if (K[DIK_S])
  2056.     {
  2057.         gui_action=102;
  2058.         vloid();
  2059.         po_ctrl=0;
  2060.     }
  2061.  
  2062.     if (K[DIK_F3])
  2063.     {
  2064.         for (int ipcop=0;ipcop<12288;ipcop++)
  2065.         {
  2066.         *(BuffPatt+ipcop)=*(RawPatterns+(pSequence[cPosition]*12288)+ipcop);
  2067.         }
  2068.  
  2069.         for (int ipcut=pSequence[cPosition]*12288;ipcut<pSequence[cPosition]*12288+12288;ipcut+=6)
  2070.         {
  2071.         *(RawPatterns+ipcut)=121;
  2072.         *(RawPatterns+ipcut+1)=255;
  2073.         *(RawPatterns+ipcut+2)=255;
  2074.         *(RawPatterns+ipcut+3)=255;
  2075.         *(RawPatterns+ipcut+4)=0;
  2076.         *(RawPatterns+ipcut+5)=0;
  2077.         }
  2078.         freakylines=patternLines[pSequence[cPosition]];        
  2079.         po_ctrl=0;
  2080.         Actupated(0);
  2081.     }
  2082.     if (K[DIK_F4])
  2083.     {
  2084.         int ipcop2=0;
  2085.         for (int ipcop=pSequence[cPosition]*12288;ipcop<pSequence[cPosition]*12288+12288;ipcop++)
  2086.         {
  2087.         *(BuffPatt+ipcop2++)=*(RawPatterns+ipcop);
  2088.         }
  2089.         vloid();po_ctrl=0;Actupated(0);
  2090.         freakylines=patternLines[pSequence[cPosition]];
  2091.     }
  2092.     if (K[DIK_F5])
  2093.     {
  2094.         int ipcop2=0;
  2095.         for (int ipcop=pSequence[cPosition]*12288;ipcop<pSequence[cPosition]*12288+12288;ipcop++)
  2096.         {
  2097.         *(RawPatterns+ipcop)=*(BuffPatt+ipcop2++);
  2098.         }
  2099.         Actupated(0);po_ctrl=0;
  2100.         patternLines[pSequence[cPosition]]=freakylines;
  2101.     }
  2102.     
  2103.     
  2104.     if (K[DIK_B])
  2105.     {
  2106.         block_start_track=ped_track;
  2107.         block_start=ped_line;
  2108.         
  2109.         if (block_end_track<block_start_track)
  2110.             block_end_track=block_start_track;
  2111.     
  2112.         if (block_end<block_start)
  2113.             block_end=block_start;
  2114.     
  2115.         if (block_end_track<0)
  2116.             block_end_track=0;
  2117.  
  2118.         Actupated(0);po_ctrl=0;
  2119.     }
  2120.     
  2121.     if (K[DIK_E])
  2122.     {
  2123.         block_end_track=ped_track;
  2124.         block_end=ped_line;
  2125.  
  2126.         if (block_start_track>block_end_track)
  2127.             block_start_track=block_end_track;
  2128.  
  2129.         if (block_start_track<0)
  2130.             block_start_track=0;
  2131.  
  2132.         if (block_start>block_end)
  2133.             block_start=block_end;
  2134.     Actupated(0);po_ctrl=0;
  2135.     }
  2136.  
  2137.  
  2138.     if (K[DIK_C] && block_start_track!=-1 && block_end_track!=-1)
  2139.     {
  2140.         int axbc=0;
  2141.         int aybc=0;
  2142.  
  2143.         for (int ybc=block_start;ybc<block_end+1;ybc++)
  2144.         {
  2145.             axbc=0;
  2146.             for (int xbc=block_start_track;xbc<block_end_track+1;xbc++)
  2147.             {
  2148.                 *(BuffBlock+axbc*6+aybc*96)=*(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96);
  2149.                 *(BuffBlock+axbc*6+aybc*96+1)=*(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+1);
  2150.                 *(BuffBlock+axbc*6+aybc*96+2)=*(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+2);
  2151.                 *(BuffBlock+axbc*6+aybc*96+3)=*(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+3);
  2152.                 *(BuffBlock+axbc*6+aybc*96+4)=*(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+4);
  2153.                 *(BuffBlock+axbc*6+aybc*96+5)=*(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+5);        
  2154.             axbc++;
  2155.             }
  2156.         aybc++;
  2157.         }
  2158.  
  2159.         b_buff_xsize=(block_end_track-block_start_track)+1;
  2160.         b_buff_ysize=(block_end-block_start)+1;
  2161.  
  2162.     Actupated(0);po_ctrl=0;
  2163.     }
  2164.  
  2165.  
  2166.     if (K[DIK_X] && block_start_track!=-1 && block_end_track!=-1)
  2167.     {
  2168.         int axbc=0;
  2169.         int aybc=0;
  2170.  
  2171.         for (int ybc=block_start;ybc<block_end+1;ybc++)
  2172.         {
  2173.             axbc=0;
  2174.             for (int xbc=block_start_track;xbc<block_end_track+1;xbc++)
  2175.             {
  2176.                 *(BuffBlock+axbc*6+aybc*96)=*(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96);
  2177.                 *(BuffBlock+axbc*6+aybc*96+1)=*(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+1);
  2178.                 *(BuffBlock+axbc*6+aybc*96+2)=*(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+2);
  2179.                 *(BuffBlock+axbc*6+aybc*96+3)=*(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+3);
  2180.                 *(BuffBlock+axbc*6+aybc*96+4)=*(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+4);
  2181.                 *(BuffBlock+axbc*6+aybc*96+5)=*(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+5);        
  2182.             
  2183.                 *(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96)=121;
  2184.                 *(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+1)=255;
  2185.                 *(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+2)=255;
  2186.                 *(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+3)=255;
  2187.                 *(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+4)=0;
  2188.                 *(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+5)=0;        
  2189.         
  2190.                 axbc++;
  2191.             }
  2192.         aybc++;
  2193.         }
  2194.  
  2195.         b_buff_xsize=(block_end_track-block_start_track)+1;
  2196.         b_buff_ysize=(block_end-block_start)+1;
  2197.  
  2198.         block_start=0;
  2199.         block_end=0;
  2200.         block_start_track=-1;
  2201.         block_end_track=-1;
  2202.  
  2203.     Actupated(0);po_ctrl=0;
  2204.     }
  2205.  
  2206.     if (K[DIK_I] && block_start_track!=-1 && block_end_track!=-1)
  2207.     {
  2208.         int axbc=0;
  2209.         int aybc=0;
  2210.  
  2211.         int startcmd=*(RawPatterns+pSequence[cPosition]*12288+block_start_track*6+block_start*96+4);
  2212.         int startvalue=*(RawPatterns+pSequence[cPosition]*12288+block_start_track*6+block_start*96+5);
  2213.         int endvalue=*(RawPatterns+pSequence[cPosition]*12288+block_start_track*6+block_end*96+5);
  2214.         int ranlen=block_end-block_start;
  2215.         if(ranlen==0)ranlen=1;
  2216.         int cran=0;
  2217.         int tran=endvalue-startvalue;
  2218.  
  2219.         for (int ybc=block_start;ybc<block_end+1;ybc++)
  2220.         {
  2221.             int c_val=(cran*tran)/ranlen;
  2222.             *(RawPatterns+pSequence[cPosition]*12288+block_start_track*6+ybc*96+4)=startcmd;
  2223.             *(RawPatterns+pSequence[cPosition]*12288+block_start_track*6+ybc*96+5)=startvalue+c_val;            
  2224.             cran++;
  2225.         }
  2226.  
  2227.     Actupated(0);po_ctrl=0;
  2228.     }
  2229.  
  2230.         if (K[DIK_R] && block_start_track!=-1 && block_end_track!=-1)
  2231.         {
  2232.         int startcmd=*(RawPatterns+pSequence[cPosition]*12288+block_start_track*6+block_start*96+4);
  2233.         
  2234.         for (int ybc=block_start;ybc<block_end+1;ybc++)
  2235.         {
  2236.             *(RawPatterns+pSequence[cPosition]*12288+block_start_track*6+ybc*96+4)=startcmd;
  2237.             *(RawPatterns+pSequence[cPosition]*12288+block_start_track*6+ybc*96+5)=rand()/128;            
  2238.         }
  2239.  
  2240.     Actupated(0);po_ctrl=0;
  2241.     }
  2242.  
  2243.     if (K[DIK_V] && b_buff_xsize!=-1 && b_buff_ysize!=-1)
  2244.     {
  2245.         int axbc=0;
  2246.         int aybc=0;
  2247.  
  2248.         for (int ybc=ped_line;ybc<ped_line+b_buff_ysize;ybc++)
  2249.         {
  2250.             axbc=0;
  2251.             for (int xbc=ped_track;xbc<ped_track+b_buff_xsize;xbc++)
  2252.             {
  2253.                 if (xbc<16 && ybc<128)
  2254.                 {
  2255.                 *(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96)=*(BuffBlock+axbc*6+aybc*96);
  2256.                 *(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+1)=*(BuffBlock+axbc*6+aybc*96+1);
  2257.                 *(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+2)=*(BuffBlock+axbc*6+aybc*96+2);
  2258.                 *(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+3)=*(BuffBlock+axbc*6+aybc*96+3);
  2259.                 *(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+4)=*(BuffBlock+axbc*6+aybc*96+4);
  2260.                 *(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+5)=*(BuffBlock+axbc*6+aybc*96+5);        
  2261.                 }
  2262.                 axbc++;
  2263.             }
  2264.             aybc++;
  2265.         }
  2266.  
  2267.     Actupated(0);po_ctrl=0;
  2268.     }
  2269.  
  2270.     if (K[DIK_Z] && b_buff_xsize!=-1 && b_buff_ysize!=-1)
  2271.     {
  2272.         int axbc=0;
  2273.         int aybc=0;
  2274.  
  2275.         for (int ybc=ped_line;ybc<ped_line+b_buff_ysize;ybc++)
  2276.         {
  2277.             axbc=0;
  2278.             for (int xbc=ped_track;xbc<ped_track+b_buff_xsize;xbc++)
  2279.             {
  2280.                 if (xbc<16 && ybc<128)
  2281.                 {
  2282.                 *(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+2)=*(BuffBlock+axbc*6+aybc*96+2);
  2283.                 *(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+3)=*(BuffBlock+axbc*6+aybc*96+3);        
  2284.                 *(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+4)=*(BuffBlock+axbc*6+aybc*96+4);
  2285.                 *(RawPatterns+pSequence[cPosition]*12288+xbc*6+ybc*96+5)=*(BuffBlock+axbc*6+aybc*96+5);        
  2286.                 }
  2287.                 axbc++;
  2288.             }
  2289.             aybc++;
  2290.         }
  2291.  
  2292.     Actupated(0);po_ctrl=0;
  2293.     }
  2294. }
  2295.  
  2296. if (K[DIK_LSHIFT] && po_shift==1)
  2297. {
  2298.     // Transpose 1 Seminote Down
  2299.  
  2300.     if (K[DIK_F1])
  2301.     {for(int lcopy=ped_line;lcopy<128;lcopy++)
  2302.     {
  2303.     int brower=*(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96));
  2304.     
  2305.     if (brower<120)
  2306.     {brower--;if (brower<0)brower=0;}
  2307.     
  2308.     *(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96))=brower;
  2309.     }
  2310.     Actupated(0);po_shift=0;
  2311.     }
  2312.  
  2313.     // Transpose 1 Seminote Up
  2314.  
  2315.     if (K[DIK_F2])
  2316.     {for(int lcopy=ped_line;lcopy<128;lcopy++)
  2317.     {
  2318.     int brower=*(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96));
  2319.     
  2320.     if (brower<120)
  2321.     {brower++;if (brower>119)brower=119;}
  2322.     
  2323.     *(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96))=brower;
  2324.     }
  2325.     Actupated(0);po_shift=0;
  2326.     }
  2327.  
  2328.     // Cut current track to Track Buffer:
  2329.  
  2330.     if (K[DIK_F3])
  2331.     {
  2332.     for(int lcopy=0;lcopy<128;lcopy++)
  2333.     {
  2334.     *(BuffTrack+(lcopy*6))=*(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96));
  2335.     *(BuffTrack+(lcopy*6)+1)=*(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96)+1);
  2336.     *(BuffTrack+(lcopy*6)+2)=*(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96)+2);
  2337.     *(BuffTrack+(lcopy*6)+3)=*(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96)+3);
  2338.     *(BuffTrack+(lcopy*6)+4)=*(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96)+4);
  2339.     *(BuffTrack+(lcopy*6)+5)=*(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96)+5);
  2340.     *(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96))=121;
  2341.     *(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96)+1)=255;
  2342.     *(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96)+2)=255;
  2343.     *(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96)+3)=255;
  2344.     *(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96)+4)=0;
  2345.     *(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96)+5)=0;
  2346.     }    
  2347.     Actupated(0);
  2348.     po_shift=0;
  2349.     }
  2350.  
  2351.     if (K[DIK_F4])
  2352.     {for(int lcopy=0;lcopy<128;lcopy++)
  2353.     {
  2354.     *(BuffTrack+(lcopy*6))=*(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96));
  2355.     *(BuffTrack+(lcopy*6)+1)=*(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96)+1);
  2356.     *(BuffTrack+(lcopy*6)+2)=*(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96)+2);
  2357.     *(BuffTrack+(lcopy*6)+3)=*(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96)+3);
  2358.     *(BuffTrack+(lcopy*6)+4)=*(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96)+4);
  2359.     *(BuffTrack+(lcopy*6)+5)=*(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96)+5);
  2360.     }
  2361.     po_shift=0;
  2362.     }
  2363.  
  2364.     // Paste Track Buffer To current Track:
  2365.  
  2366.     if (K[DIK_F5])
  2367.     {for(int lcopy=0;lcopy<128;lcopy++)
  2368.     {
  2369.     *(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96))=*(BuffTrack+(lcopy*6));
  2370.     *(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96)+1)=*(BuffTrack+(lcopy*6)+1);
  2371.     *(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96)+2)=*(BuffTrack+(lcopy*6)+2);
  2372.     *(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96)+3)=*(BuffTrack+(lcopy*6)+3);
  2373.     *(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96)+4)=*(BuffTrack+(lcopy*6)+4);
  2374.     *(RawPatterns+pSequence[cPosition]*12288+(ped_track*6)+(lcopy*96)+5)=*(BuffTrack+(lcopy*6)+5);
  2375.     }
  2376.     Actupated(0);
  2377.     po_shift=0;
  2378.     }
  2379. }
  2380. if (K[DIK_LSHIFT]){poskeynote=1;poskeyval=1;}
  2381. if (poskeyval==0 && retvalue!=ltretvalue)poskeyval=1;
  2382.  
  2383. if ( (ped_row==1 || ped_row==3 || ped_row==5 || ped_row==7 || ped_row==9) && retvalue!=120 && poskeyval==1  && is_editing==1)
  2384. {
  2385.  
  2386.     int ped_cell=1;
  2387.     if (ped_row==3)ped_cell=2;
  2388.     if (ped_row==5)ped_cell=3;
  2389.     if (ped_row==7)ped_cell=4;
  2390.     if (ped_row==9)ped_cell=5;
  2391.     ltretvalue=retvalue;
  2392.     xoffseted=(ped_track*6)+(ped_line*96)+ped_cell;
  2393.     
  2394.     int oldval=*(RawPatterns+pSequence[cPosition]*12288+xoffseted);
  2395.     
  2396.     if (retvalue<16)
  2397.     {
  2398.     if (oldval==255 && ped_row==1)oldval=0;
  2399.     if (oldval==255 && ped_row==3)oldval=0;
  2400.     if (oldval==255 && ped_row==5)oldval=0;
  2401.     oldval=(oldval&0xf)+retvalue*16;
  2402.     }
  2403.     else
  2404.     {
  2405.     oldval=0;
  2406.     if (ped_row==1)oldval=255;
  2407.     if (ped_row==3)oldval=255;
  2408.     if (ped_row==5)oldval=255;
  2409.     }
  2410.  
  2411.     *(RawPatterns+pSequence[cPosition]*12288+xoffseted)=oldval;
  2412.     
  2413.     
  2414.     if(oldval!=255 && ped_row==5 && *(RawPatterns+pSequence[cPosition]*12288+xoffseted)>144)
  2415.     *(RawPatterns+pSequence[cPosition]*12288+xoffseted)=144;
  2416.     
  2417.     ped_line+=ped_pattad;
  2418.     Actupated(0);
  2419.     poskeyval=0;
  2420. }
  2421.  
  2422. if ( (ped_row==2 || ped_row==4 || ped_row==6 || ped_row==8 || ped_row==10) && retvalue!=120 && is_editing==1 && poskeyval==1)
  2423. {
  2424.     int ped_cell=1;
  2425.     if (ped_row==2)ped_cell=1;
  2426.     if (ped_row==4)ped_cell=2;
  2427.     if (ped_row==6)ped_cell=3;
  2428.     if (ped_row==8)ped_cell=4;
  2429.     if (ped_row==10)ped_cell=5;
  2430.     
  2431.     ltretvalue=retvalue;
  2432.     xoffseted=(ped_track*6)+(ped_line*96)+ped_cell;
  2433.     int oldval=*(RawPatterns+pSequence[cPosition]*12288+xoffseted);
  2434.     
  2435.     if (retvalue<16)
  2436.     {
  2437.     if (oldval==255 && ped_row==2)oldval=0;
  2438.     if (oldval==255 && ped_row==4)oldval=0;
  2439.     if (oldval==255 && ped_row==6)oldval=0;
  2440.     oldval=(oldval&0xf0)+retvalue;
  2441.     }
  2442.     else
  2443.     {
  2444.     oldval=0;
  2445.     if (ped_row==2)oldval=255;
  2446.     if (ped_row==4)oldval=255;
  2447.     if (ped_row==6)oldval=255;
  2448.     }
  2449.  
  2450.     *(RawPatterns+pSequence[cPosition]*12288+xoffseted)=oldval;
  2451.     
  2452.     if(oldval!=255 && ped_row==6 && *(RawPatterns+pSequence[cPosition]*12288+xoffseted)>144)
  2453.     *(RawPatterns+pSequence[cPosition]*12288+xoffseted)=144;
  2454.  
  2455.     ped_line+=ped_pattad;
  2456.     Actupated(0);
  2457.     poskeyval=0;
  2458. }
  2459.  
  2460. if (poskeynote==0 && retnote!=ltretnote)poskeynote=1;
  2461.   if (ped_row==0 && poskeynote==1 && retnote!=120)
  2462.   {
  2463.      ltretnote=retnote;
  2464.  
  2465.     xoffseted=ped_track*6+ped_line*96+pSequence[cPosition]*12288;
  2466.     
  2467.     int tmp_note=retnote+ped_patoct*12;
  2468.     if (tmp_note>119)tmp_note=119;
  2469.     
  2470.     if (retnote>-1)
  2471.     {
  2472.     if (is_editing){
  2473.     *(RawPatterns+xoffseted)=tmp_note; //121
  2474.     *(RawPatterns+xoffseted+1)=ped_patsam; //121
  2475.     if (!Songplaying)ped_line+=ped_pattad;
  2476.     Actupated(0);
  2477.     }
  2478.  
  2479.     if (c_midiout!=-1)midiOutShortMsg(midiout_handle, (176+TRACKMIDICHANNEL[ped_track]) | (123 << 8) | (0 << 16)); 
  2480.     
  2481.     Sp_Playwave(ped_track, (float)tmp_note, ped_patsam,CustomVol[ped_patsam],0,0);
  2482.     }
  2483.  
  2484.     if (retnote==-3)
  2485.     {
  2486.     *(RawPatterns+xoffseted)=120; //121
  2487.     if (!Songplaying)ped_line+=ped_pattad;
  2488.     Actupated(0);
  2489.     
  2490.     }
  2491.  
  2492.     if (retnote==-1)
  2493.     {
  2494.     *(RawPatterns+xoffseted)=121; //121
  2495.     *(RawPatterns+xoffseted+1)=255; //121
  2496.     if (!Songplaying)ped_line+=ped_pattad;
  2497.     Actupated(0);
  2498.     }
  2499.  
  2500.     if (retnote==-2)
  2501.     {
  2502.     for (int interval=126;interval>ped_line-1;interval--)
  2503.     {
  2504.     xoffseted=ped_track*6+interval*96+pSequence[cPosition]*12288;
  2505.     *(RawPatterns+xoffseted+96)=*(RawPatterns+xoffseted);
  2506.     *(RawPatterns+xoffseted+97)=*(RawPatterns+xoffseted+1);
  2507.     *(RawPatterns+xoffseted+98)=*(RawPatterns+xoffseted+2);
  2508.     *(RawPatterns+xoffseted+99)=*(RawPatterns+xoffseted+3);
  2509.     *(RawPatterns+xoffseted+100)=*(RawPatterns+xoffseted+4);
  2510.     *(RawPatterns+xoffseted+101)=*(RawPatterns+xoffseted+5);
  2511.     
  2512.     }
  2513.     xoffseted=(ped_track*6)+(ped_line*96)+pSequence[cPosition]*12288;
  2514.     *(RawPatterns+xoffseted)=121;
  2515.     *(RawPatterns+xoffseted+1)=255;
  2516.     *(RawPatterns+xoffseted+2)=255;
  2517.     *(RawPatterns+xoffseted+3)=255;
  2518.     *(RawPatterns+xoffseted+4)=0;
  2519.     *(RawPatterns+xoffseted+5)=0;
  2520.     Actupated(0);
  2521.     }
  2522.  
  2523.     // BACKSPACE
  2524.  
  2525.     if (retnote==-4)
  2526.     {
  2527.     for (int interval=ped_line+1;interval<128;interval++)
  2528.     {
  2529.     xoffseted=ped_track*6+interval*96+pSequence[cPosition]*12288;
  2530.     int xoffseted2=pSequence[cPosition]*12288+ped_track*6+(interval*96)-96;
  2531.  
  2532.     *(RawPatterns+xoffseted2)=*(RawPatterns+xoffseted);
  2533.     *(RawPatterns+xoffseted2+1)=*(RawPatterns+xoffseted+1);
  2534.     *(RawPatterns+xoffseted2+2)=*(RawPatterns+xoffseted+2);
  2535.     *(RawPatterns+xoffseted2+3)=*(RawPatterns+xoffseted+3);
  2536.     *(RawPatterns+xoffseted2+4)=*(RawPatterns+xoffseted+4);
  2537.     *(RawPatterns+xoffseted2+5)=*(RawPatterns+xoffseted+5);
  2538.     }
  2539.  
  2540.     xoffseted=(ped_track*6)+12192+pSequence[cPosition]*12288;
  2541.     *(RawPatterns+xoffseted)=121;
  2542.     *(RawPatterns+xoffseted+1)=255;
  2543.     *(RawPatterns+xoffseted+2)=255;
  2544.     *(RawPatterns+xoffseted+3)=255;
  2545.     *(RawPatterns+xoffseted+4)=0;
  2546.     *(RawPatterns+xoffseted+5)=0;
  2547.  
  2548.     Actupated(0);
  2549.     }
  2550.  
  2551.     poskeynote=0;
  2552.   }
  2553.   if (Songplaying && player_pos!=cPosition){vloid();gui_action=200;}
  2554.   if (GUIMODE)S->flip();
  2555.   return 0;
  2556. }
  2557.  
  2558. void guiDial(int x,int y, int sx,int sy,const char* str,int brill)
  2559. {
  2560.     x++;
  2561.     y++;
  2562.     int tbrill1=brill-32;
  2563.     int tbrill2=brill/4;
  2564.     int tbrill3=brill/2;
  2565.     int x2=x+sx;
  2566.     int y2=y+sy;
  2567.     
  2568.     if(brill!=100){
  2569.     S->setColor(brill,brill,brill);
  2570.     S->line(x, y,x2,y);
  2571.     
  2572.     S->setColor(tbrill1,tbrill1,tbrill1);
  2573.     S->line(x,y+2,x,y2);
  2574.  
  2575.     S->setColor(tbrill2,tbrill2,tbrill2);
  2576.     S->line(x+2,y2,x2,y2);
  2577.     S->line(x2,y+2,x2,y2);
  2578.     }else{
  2579.     S->setColor(brill,brill,brill);
  2580.     S->line(x+2,y2,x2,y2);
  2581.     
  2582.     S->setColor(tbrill1,tbrill1,tbrill1);
  2583.     S->line(x2,y+2,x2,y2);
  2584.     
  2585.     S->setColor(tbrill2,tbrill2,tbrill2);
  2586.     S->line(x, y,x2,y);
  2587.     S->line(x,y+2,x,y2);
  2588.     }
  2589.     
  2590.     S->setColor(tbrill3,tbrill3,tbrill3);
  2591.  
  2592.     for (int filler=y+2;filler<y2;filler+=2)
  2593.     S->line(x+2,filler,x2-2,filler);    
  2594.     S->printXY(x+3, y+1, 0x00DDFFFF, str);    
  2595. }
  2596.  
  2597. void guiDial2(const char* str)
  2598. {
  2599.  
  2600.     S->setColor(0,72,72);
  2601.  
  2602.     for (int filler=330;filler<452;filler+=2)
  2603.     S->line(3,filler,637,filler);
  2604.     
  2605.     S->printXY(5, 330, 0x00112211, str);    
  2606.     S->printXY(4, 329, 0x00DDFFFF, str);    
  2607. }
  2608.  
  2609. void Read_SMPT(void)
  2610. {
  2611.     lt_ykar=0;
  2612.     lt_items=0;    
  2613.     int list_counter=0;
  2614.     lt_curr=0;
  2615.     lt_index=0;
  2616.     struct _finddata_t c_file;    
  2617.     long hFile;
  2618.   
  2619.     /* Find first .c file in current directory */
  2620.     
  2621.     if( (hFile = _findfirst( "*.*", &c_file )) == -1L )
  2622.     {
  2623.         sprintf(SMPT_LIST[0],"No files in current dir.");
  2624.         FILETYPE[0]=0;
  2625.         lt_items=1;
  2626.     }
  2627.     else   
  2628.     {
  2629.     // The first file
  2630.     sprintf(SMPT_LIST[list_counter],c_file.name);
  2631.     FILETYPE[list_counter]=c_file.attrib&_A_SUBDIR;
  2632.     lt_items++;
  2633.     list_counter++;
  2634.     
  2635.     /* Find the rest of the files (directorys)*/
  2636.     
  2637.     while( _findnext( hFile, &c_file ) == 0 )            
  2638.     {
  2639.         if (c_file.attrib&_A_SUBDIR)
  2640.         {
  2641.         sprintf(SMPT_LIST[list_counter],c_file.name);
  2642.         FILETYPE[list_counter]=_A_SUBDIR;
  2643.         lt_items++;
  2644.         list_counter++;
  2645.         }
  2646.     }
  2647.     // End dir
  2648.     _findclose( hFile );
  2649.     }
  2650.  
  2651.     if( (hFile = _findfirst( "*.*", &c_file )) == -1L )
  2652.     {
  2653.         sprintf(SMPT_LIST[0],"No files in current dir.");
  2654.         FILETYPE[0]=0;
  2655.         lt_items=1;
  2656.     }
  2657.     else   
  2658.     {
  2659.     // The first file (files)
  2660.     if (!(c_file.attrib&_A_SUBDIR))
  2661.     {
  2662.     sprintf(SMPT_LIST[list_counter],c_file.name);
  2663.     FILETYPE[list_counter]=0;
  2664.     lt_items++;
  2665.     list_counter++;
  2666.     }
  2667.     /* Find the rest of the files (files)*/
  2668.     while( _findnext( hFile, &c_file ) == 0 )            
  2669.     {
  2670.     if (!(c_file.attrib&_A_SUBDIR))
  2671.     {
  2672.     sprintf(SMPT_LIST[list_counter],c_file.name);
  2673.     FILETYPE[list_counter]=0;
  2674.     lt_items++;
  2675.     list_counter++;
  2676.     }
  2677.  
  2678.     } // while      
  2679.     
  2680.     _findclose( hFile );
  2681.     
  2682.     }
  2683.  
  2684.     /* Save current drive. */   
  2685.     int curdrive = _getdrive();
  2686.  
  2687.     for (int drivex=1;drivex<16;drivex++)
  2688.     {
  2689.     sprintf(SMPT_LIST[list_counter],"%c:", drivex + 'A' - 1 );
  2690.     FILETYPE[list_counter]=_A_SUBDIR;
  2691.     list_counter++;
  2692.     lt_items++;
  2693.     }
  2694.     _chdrive(curdrive);
  2695. }
  2696.  
  2697. void DumpList(int xr,int yr,int y)
  2698. {
  2699.     S->setColor(12,22,30);
  2700.  
  2701.     bjbox(xr,yr,226+restx,136);
  2702.  
  2703.     char buffer[64];   /* Get the current working directory: */
  2704.     
  2705.     guiDial(454,24,184+restx,16,"",100);
  2706.         
  2707.     if( _getcwd( buffer,48) == NULL )     
  2708.     S->printXY(458,26,0x00ffffff,"Cannot fit path here...");
  2709.     else
  2710.     S->printXY(458,26,0x00ffffff,buffer);
  2711.  
  2712.     for (int counter=0;counter<11;counter++)
  2713.     {
  2714.     int rel_val=y+counter;
  2715.     
  2716.     if (y+counter==lt_curr)
  2717.     {
  2718.     S->setColor(12,52,160);
  2719.     bjbox(xr,yr+(counter*12)+2,226+restx,12);
  2720.     }    
  2721.  
  2722.     if (y+counter<lt_items)
  2723.         
  2724.         if (FILETYPE[rel_val]==_A_SUBDIR)
  2725.         {
  2726.             S->printXY(xr,yr+(counter*12), 0x0044ff88,"/");        
  2727.             S->printXY(xr+8,yr+(counter*12), 0x00ffffff,SMPT_LIST[rel_val]);        
  2728.         }
  2729.         else
  2730.         {
  2731.             S->printXY(xr,yr+(counter*12), 0x00aabbcc,SMPT_LIST[rel_val]);        
  2732.         }
  2733.     }
  2734. }
  2735.  
  2736. void bjbox(int x,int y,int sx,int sy)
  2737. {
  2738. for (int filler=y;filler<y+sy;filler+=2)
  2739.     S->line(x,filler,x+sx,filler);
  2740. }
  2741.  
  2742. void ltActualize(int modeac)
  2743. {
  2744. int const brolim=lt_items-11;
  2745.  
  2746. if (modeac==0)
  2747. {
  2748. if (lt_ykar>70)
  2749. lt_ykar=70;
  2750.  
  2751. if (lt_ykar<0)
  2752. lt_ykar=0;
  2753.  
  2754. lt_index=(lt_ykar*brolim)/70;
  2755. }
  2756.  
  2757. if (lt_index>brolim)
  2758. lt_index=brolim;
  2759.  
  2760. if (lt_index<0)
  2761. lt_index=0;
  2762.  
  2763. if (modeac!=0)
  2764. lt_ykar=(lt_index*70)/brolim;
  2765.  
  2766. S->setColor(40,50,60);
  2767. bjbox(395,59,16,103);
  2768. guiDial(394,58+lt_ykar,16,32,"",200);
  2769. if (last_index!=lt_index){DumpList(413,43,lt_index);last_index=lt_index;}
  2770. }
  2771.  
  2772. char zcheckMouse(int x,int y,int xs,int ys)
  2773. {
  2774.     char scape=0;
  2775.  
  2776.     if (gui_pushed==0 && LastX>x && LastX<x+xs && LastY>y && LastY<y+ys)
  2777.     {
  2778.     gui_lx=x;
  2779.     gui_ly=y;
  2780.     gui_pushed=1;
  2781.     scape=1;
  2782.     fluzy=-1;
  2783.     }
  2784.  
  2785.     if (gui_pushed==1 && x==gui_lx && y==gui_ly)
  2786.     scape=1;
  2787.  
  2788.     return scape;
  2789. }
  2790.  
  2791. void vloid(void)
  2792. {
  2793. if(!GUIMODE)S->copy(MOUSEBACK, LastX-1, LastY-1,0,0, 10,18,0);
  2794. }
  2795.  
  2796. // Bank initializer ---------------------------------------------
  2797.  
  2798. void init_sample_bank(void)
  2799. {
  2800.     RESET303PARAMETERS(&tb303[0]);
  2801.     RESET303PARAMETERS(&tb303[1]);
  2802.  
  2803.     for (int inico=0;inico<256;inico++)
  2804.     {
  2805.  
  2806. // All tracks actived on entire sequence (1-Active 0-Inactive)
  2807.  
  2808.     for (int inico2=0;inico2<MAX_TRACKS;inico2++)
  2809.         SACTIVE[inico][inico2]=true;
  2810.  
  2811.     pSequence[inico]=0;
  2812.  
  2813.     if(inico<128){
  2814.     beatsync[inico]=false;
  2815.     beatlines[inico]=16;
  2816.  
  2817.     sprintf(nameins[inico],"Unnamed");
  2818.     ResetSynthParameters(&PARASynth[inico]);
  2819.     
  2820.     for (int ced_split=0;ced_split<16;ced_split++)
  2821.     {
  2822.     RawSamples[inico][0][ced_split]=NULL;
  2823.     RawSamples[inico][1][ced_split]=NULL;
  2824.     SampleChannels[inico][ced_split]=0;
  2825.     SampleType[inico][ced_split]=0;
  2826.     LoopStart[inico][ced_split]=0;
  2827.     LoopEnd[inico][ced_split]=0;
  2828.     LoopType[inico][ced_split]=0;
  2829.     SampleNumSamples[inico][ced_split]=0;
  2830.     Finetune[inico][ced_split]=0;
  2831.     SampleVol[inico][ced_split]=0.0f;
  2832.     FDecay[inico][ced_split]=0.0;
  2833.     Basenote[inico][ced_split]=48;
  2834.     sprintf(SampleName[inico][ced_split],"Unnamed");
  2835.     Midiprg[inico]=-1;
  2836.     Synthprg[inico]=false;
  2837.     CustomVol[inico]=1.0f;
  2838.     }
  2839. }}
  2840. }
  2841.  
  2842. void AllocateWave(int n_index, long lenfir, int samplechans)
  2843. {
  2844.  
  2845. // Freeing if memory was allocated before -----------------------
  2846.  
  2847.     if (SampleType[n_index][ped_split]!=0)
  2848.     {
  2849.         free(RawSamples[n_index][0][ped_split]);
  2850.  
  2851.         if (SampleChannels[n_index][ped_split]==2)
  2852.         free(RawSamples[n_index][1][ped_split]);
  2853.     }
  2854.  
  2855.     SampleType[n_index][ped_split]=1;
  2856.     SampleChannels[n_index][ped_split]=samplechans;
  2857.     RawSamples[n_index][0][ped_split]=(short *)malloc(lenfir*2);
  2858.     
  2859.     if (samplechans==2)
  2860.     RawSamples[n_index][1][ped_split]=(short *)malloc(lenfir*2);        
  2861.  
  2862.     LoopStart[n_index][ped_split]=0;
  2863.     LoopEnd[n_index][ped_split]=lenfir;
  2864.     LoopType[n_index][ped_split]=0;
  2865.     SampleNumSamples[n_index][ped_split]=lenfir;
  2866.     Finetune[n_index][ped_split]=0;
  2867.     SampleVol[n_index][ped_split]=1.0;
  2868. }
  2869.  
  2870. void WavAlloc(int Freeindex,const char * str)
  2871. {
  2872.     long Datalen=0;
  2873.     int ld0=0,ld1=0,ld2=0,ld3=0;
  2874.     int Freeindex2=0;
  2875.     int idchk=0;
  2876.     FILE *in;
  2877.     
  2878.     int rate=0;
  2879.     int bits=0;
  2880.     short *csamples,*csamples2;
  2881.     char st_type=0;
  2882.     short inx=0;
  2883.     int fmtchklen=0;
  2884.  
  2885.     const char *Wavfile=str;
  2886.     idchk=0;
  2887.  
  2888.     if (Wavfile!=NULL && (in = fopen(Wavfile,"rb"))!=NULL)
  2889.     {
  2890.     char extension[10];
  2891.     char modext[5];
  2892.     char rebext[5];
  2893.     
  2894.     sprintf(modext,"NTK.");
  2895.     sprintf(rebext,"NTK.");
  2896.  
  2897.     fseek(in,1080,SEEK_SET);
  2898.     fread(modext, sizeof( char),4,in);
  2899.     
  2900.     fseek(in,0,SEEK_SET);
  2901.     fread(extension, sizeof( char),9,in);
  2902.     
  2903.     fseek(in,8,SEEK_SET);
  2904.     fread(rebext, sizeof( char),4,in);
  2905.     
  2906.     if (strcmp(rebext,"RB40")==0)
  2907.     {
  2908.     sprintf(name,"%s",Wavfile);
  2909.     LoadRebirthMod();
  2910.     }
  2911.     else if (strcmp(modext,"M.K.")==0 || strcmp(modext,"M!K!")==0 || strcmp(modext,"FLT4")==0  || strcmp(modext,"4CHN")==0)
  2912.     {
  2913.     sprintf(name,"%s",Wavfile);
  2914.     LoadAmigaMod();
  2915.     NewWavy();
  2916.     }
  2917.     else if (strcmp(extension,"TWNNINS0")==0)
  2918.     {
  2919.     sprintf(name,"%s",Wavfile);
  2920.     LoadInst();
  2921.     NewWavy();
  2922.     }
  2923.     else if (strcmp(extension,"TWNNSNG0")==0 || strcmp(extension,"TWNNSNG1")==0)
  2924.     {
  2925.     mess_box("Sorry, old beta versions .ntk soundformats is not supported.");
  2926.     }
  2927.     else if (strcmp(extension,"TWNNSNG2")==0)
  2928.     {
  2929.     sprintf(name,"%s",Wavfile);
  2930.     LoadMod();
  2931.     NewWavy();
  2932.     }
  2933.     else if (strcmp(extension,"TWNNSYN0")==0)
  2934.     {
  2935.     sprintf(name,"%s",Wavfile);
  2936.     LoadSynth();
  2937.     }
  2938.     else
  2939.     {
  2940.     mess_box("Attempting of loading a wav file...");    
  2941.     
  2942.     fseek(in,8,SEEK_SET);
  2943.     idchk=fgetc(in)*fgetc(in)*fgetc(in)*fgetc(in);
  2944.     
  2945.     if (idchk==33556770)
  2946.     {
  2947.         rewind(in);
  2948.         fseek(in,22,SEEK_SET);
  2949.         st_type=fgetc(in);
  2950.         
  2951.         fseek(in,24,SEEK_SET);
  2952.         rate=fgetc(in);
  2953.         rate+=fgetc(in)*256;
  2954.  
  2955.         fseek(in,34,SEEK_SET);
  2956.         bits=fgetc(in);
  2957.         
  2958.         fseek(in,16,SEEK_SET); /* Get length of fmtchk */
  2959.         fmtchklen=fgetc(in);
  2960.         
  2961.         // Set cursor at possible list
  2962.         fseek(in,20+fmtchklen,SEEK_SET);
  2963.         unsigned int lchk=0;
  2964.         fread(&lchk,4,1,in);
  2965.         
  2966.         if(lchk==1414744396)
  2967.         {
  2968.         fmtchklen+=8;// LIST HANDLED!
  2969.  
  2970.         // handling size of LIST chunk
  2971.         unsigned char lelist;
  2972.         fread(&lelist,1,1,in);
  2973.         fmtchklen+=lelist;
  2974.         }
  2975.  
  2976.         fseek(in,24+fmtchklen,SEEK_SET);
  2977.         ld0=fgetc(in);
  2978.         
  2979.         fseek(in,25+fmtchklen,SEEK_SET);
  2980.         ld1=fgetc(in);
  2981.         
  2982.         fseek(in,26+fmtchklen,SEEK_SET);
  2983.         ld2=fgetc(in);
  2984.         
  2985.         fseek(in,27+fmtchklen,SEEK_SET);
  2986.         ld3=fgetc(in);
  2987.         
  2988.         Datalen=(ld3*16777216)+(ld2*65536)+(ld1*256)+ld0;
  2989.         
  2990.         if (bits==16)Datalen/=2;
  2991.         
  2992.         if (st_type==2)Datalen/=2;
  2993.         
  2994.         if (st_type==2)
  2995.         {
  2996.         AllocateWave(Freeindex, Datalen,2);
  2997.         csamples=RawSamples[Freeindex][0][ped_split];
  2998.         csamples2=RawSamples[Freeindex][1][ped_split];
  2999.         }
  3000.         else
  3001.         {
  3002.         AllocateWave(Freeindex, Datalen,1);
  3003.         csamples=RawSamples[Freeindex][0][ped_split];
  3004.         }
  3005.  
  3006.         fseek(in,28+fmtchklen,SEEK_SET);
  3007.         
  3008.         for(long io=0;io<Datalen;io++)
  3009.         {
  3010.             if (bits==8)
  3011.             {
  3012.                 inx=fgetc(in)*256;
  3013.             }
  3014.             else
  3015.             {
  3016.             inx=fgetc(in);
  3017.             inx+=fgetc(in)*256;
  3018.             }
  3019.             
  3020.             if (st_type==2 && bits==16)
  3021.             {
  3022.             *csamples2=fgetc(in);
  3023.             *csamples2+=fgetc(in)*256;
  3024.             *csamples2-=65536;
  3025.             csamples2++;
  3026.             }
  3027.  
  3028.             if (st_type==2 && bits==8)
  3029.             {
  3030.             *csamples2=(fgetc(in)*256)-32768;
  3031.             csamples2++;
  3032.             }
  3033.             
  3034.             if (bits==16)
  3035.             *csamples=inx-65536;
  3036.             else
  3037.             *csamples=inx-32768;
  3038.             csamples++;
  3039.         }
  3040.  
  3041.         sprintf(SampleName[Freeindex][ped_split],"%s",Wavfile); 
  3042.  
  3043.  
  3044.         if (st_type==1 && bits==8)
  3045.         mess_box("Mono 8-Bits WAV PCM loaded");    
  3046.     
  3047.         if (st_type==1 && bits==16)
  3048.         mess_box("Mono 16-Bits WAV PCM loaded");    
  3049.     
  3050.         if (st_type==2 && bits==8)
  3051.         mess_box("Stereo 8-Bits WAV PCM loaded");    
  3052.     
  3053.         if (st_type==2 && bits==16)
  3054.         mess_box("Stereo 16-Bits WAV PCM loaded");    
  3055.  
  3056.         
  3057.         char smpc[16];
  3058.         smpc[4]=0;
  3059.         fread(&smpc,4,1,in);
  3060.         if(strcmp("smpl",smpc)==0)
  3061.         {
  3062.             // Loop Found
  3063.         
  3064.             //    fseek(in,48,SEEK_CUR);
  3065.  
  3066.             fseek(in,32,SEEK_CUR);
  3067.  
  3068.             char pl=0;
  3069.  
  3070.             fread(&pl,1,1,in);
  3071.             
  3072.             if(pl==1)
  3073.             {
  3074.             fseek(in,15,SEEK_CUR);
  3075.  
  3076.             unsigned int ls=0;
  3077.             unsigned int le=0;
  3078.             fread(&ls,sizeof(int),1,in);
  3079.             fread(&le,sizeof(int),1,in);
  3080.             LoopStart[Freeindex][ped_split]=ls;
  3081.             LoopEnd[Freeindex][ped_split]=le;
  3082.             LoopType[Freeindex][ped_split]=1;
  3083.             }
  3084.         }
  3085.         
  3086.         Actualize_Patterned();
  3087.         Actualize_Sample_Ed(2,0);
  3088.         fclose(in);
  3089.         NewWavy();
  3090.     }
  3091.     else
  3092.     {
  3093.     mess_box("Invalid file ID format. I accept only '.wav' '.ntk' '.nti' or '.nts' or Amiga 'MOD' files.");
  3094.     fclose(in);
  3095.     }
  3096.     }
  3097.     }
  3098.     else
  3099.     {
  3100.     mess_box("File loading error. (Probably: file not found)");    
  3101.     }
  3102.     Actualize_Main_Ed();
  3103. }
  3104.  
  3105. // Function that search for a free wave on board ----------------
  3106.  
  3107. int GetFreeWave(void)
  3108. {
  3109.     int inico=0;
  3110.     int exiter=0;
  3111.     int valuer=-1;
  3112.  
  3113.     do{
  3114.     
  3115.     if (SampleType[inico]==0)
  3116.     {
  3117.         exiter=1;
  3118.         valuer=inico;
  3119.     }
  3120.     inico++;
  3121.     }while(exiter==0);
  3122.     
  3123.     return valuer;
  3124. }
  3125.  
  3126. void mess_box(char const *str)
  3127. {
  3128. guiDial3(0,CONSOLE_HEIGHT-21,fsize,18,str,220);
  3129. }
  3130.         
  3131. #include "noisetrekkerp2.cpp"
  3132.  
  3133. void Actualize_Sequencer(void)
  3134. {
  3135.  
  3136. valuer_box2(188,60,cPosition);
  3137. valuer_box2(188,78,pSequence[cPosition]);
  3138. Anat(cPosition);
  3139. valuer_box2(188,96,sLength);
  3140. valuer_box(188,114,patternLines[pSequence[cPosition]]);
  3141.  
  3142. if (userscreen==4)Actualize_Seq_Ed();
  3143. }
  3144.  
  3145. int AllocPattern(void)
  3146. {
  3147. for (int api=0;api<128;api++)
  3148. patternLines[api]=64;
  3149.  
  3150. nPatterns=1;
  3151.  
  3152. if ((RawPatterns=(unsigned char *)malloc(PBLEN))!=NULL) // 6144 bytes per pattern
  3153. {
  3154.     for (int inicial=0;inicial<PBLEN;inicial+=6)
  3155.     {
  3156.     *(RawPatterns+inicial)=121;//121
  3157.     *(RawPatterns+inicial+1)=255;//255
  3158.     *(RawPatterns+inicial+2)=255;//255
  3159.     *(RawPatterns+inicial+3)=255;//255
  3160.     *(RawPatterns+inicial+4)=0;//0
  3161.     *(RawPatterns+inicial+5)=0;//0
  3162.     }
  3163. return 1; // Allocated
  3164. }
  3165. else
  3166. {
  3167. return 0; // Not allocated
  3168. }
  3169.  
  3170. } // End of alloc pattern
  3171.  
  3172. void FreeAll(void)
  3173. {
  3174.     // Freeing Allocated Samples
  3175.  
  3176.     for (int freer=0;freer<128;freer++)
  3177.     {
  3178.         for(char pedsplit=0;pedsplit<16;pedsplit++)
  3179.         {
  3180.         if (SampleType[freer][pedsplit]!=0)
  3181.         {free(RawSamples[freer][0][pedsplit]);
  3182.         if (SampleChannels[freer][pedsplit]==2)free(RawSamples[freer][1][pedsplit]);}
  3183.         }
  3184.     }
  3185. }
  3186.  
  3187. void draw_pated(int pattern,int track, int line, int petrack, int row)
  3188. {
  3189. S->endDraw();
  3190.  
  3191. int rel=0;
  3192. int offset_t;
  3193. int dover=0;
  3194. int color=0;
  3195. int ypb1=9;
  3196. int ypb2=16;
  3197. bool multip=false;
  3198.  
  3199. int tvisiblecolums=visiblecolums;
  3200. if (tvisiblecolums>Songtracks)
  3201. tvisiblecolums=Songtracks;
  3202.  
  3203. for (int liner=0;liner<tvisiblecolums;liner++)
  3204. {
  3205.     color=liner*118;
  3206.  
  3207.     if(SACTIVE[cPosition][track+liner])
  3208.     Letter(82+color,187,23,0,0);
  3209.     else
  3210.     Letter(82+color,187,24,0,0);
  3211.     
  3212.     if(TRACKSTATE[track+liner])
  3213.     Letter(51+color,187,25,0,0);
  3214.     else
  3215.     Letter(51+color,187,26,0,0);
  3216.     
  3217.     Letter(72+color,186,liner+track,18,25);
  3218.     
  3219. }
  3220.  
  3221. int y=YVIEW+VIEWLINE2*8;
  3222.         
  3223. for (liner=VIEWLINE2;liner<VIEWLINE;liner++)
  3224.     {
  3225.     rel=liner+line;
  3226.  
  3227.     if (rel>-1 && rel<patternLines[pSequence[cPosition]])
  3228.         {
  3229.         
  3230.         if (liner!=0)
  3231.         {
  3232.         if(rel%4==0)
  3233.             multip=true;
  3234.         else
  3235.             multip=false;
  3236.  
  3237.         if(multip)
  3238.         {
  3239.         Letter(0,y,rel>>4,121,128);
  3240.         Letter(8,y,rel&0xf,121,128);
  3241.         }
  3242.         else
  3243.         {
  3244.         Letter(0,y,rel>>4,0,7);
  3245.         Letter(8,y,rel&0xf,0,7);
  3246.         }
  3247.         
  3248.         for (int tracky=0;tracky<tvisiblecolums;tracky++)
  3249.             {
  3250.             
  3251.             if (track+tracky>=block_start_track && track+tracky<=block_end_track && rel>=block_start && rel<=block_end){ypb1=9;ypb2=16;}else{ypb1=0;ypb2=7;}
  3252.             
  3253.             if(multip){ypb1+=121;ypb2+=121;}
  3254.  
  3255.             dover=tracky*118;
  3256.             offset_t=(rel*96+((track+tracky)*6))+pattern*12288;
  3257.             
  3258.             unsigned char p_a=*(RawPatterns+offset_t);
  3259.             unsigned char p_b=*(RawPatterns+offset_t+1);
  3260.             unsigned char p_bh=p_b&0xf;
  3261.             unsigned char p_c=*(RawPatterns+offset_t+2);
  3262.             unsigned char p_ch=p_c&0xf;
  3263.             unsigned char p_d=*(RawPatterns+offset_t+3);
  3264.             unsigned char p_dh=p_d&0xf;
  3265.             unsigned char p_e=*(RawPatterns+offset_t+4);
  3266.             unsigned char p_eh=p_e&0xf;
  3267.             unsigned char p_f=*(RawPatterns+offset_t+5);
  3268.             unsigned char p_fh=p_f&0xf;
  3269.             
  3270.             blitnote(24+dover,y,p_a,ypb1,ypb2);
  3271.             
  3272.             if(p_b!=255)
  3273.             {
  3274.             Letter(48+dover,y,p_b>>4,ypb1,ypb2);
  3275.             Letter(56+dover,y,p_bh,ypb1,ypb2);
  3276.             }
  3277.             else
  3278.             {
  3279.             Letter(48+dover,y,21,ypb1,ypb2);
  3280.             Letter(56+dover,y,21,ypb1,ypb2);
  3281.             }
  3282.  
  3283.             if(p_c!=255)
  3284.             {
  3285.             Letter(64+dover,y,p_c>>4,ypb1,ypb2);
  3286.             Letter(72+dover,y,p_ch,ypb1,ypb2);
  3287.             }
  3288.             else
  3289.             {
  3290.             Letter(64+dover,y,21,ypb1,ypb2);
  3291.             Letter(72+dover,y,21,ypb1,ypb2);
  3292.             }
  3293.  
  3294.             if(p_d!=255)
  3295.             {
  3296.             Letter(80+dover,y,p_d>>4,ypb1,ypb2);
  3297.             Letter(88+dover,y,p_dh,ypb1,ypb2);
  3298.             }
  3299.             else
  3300.             {
  3301.             Letter(80+dover,y,21,ypb1,ypb2);
  3302.             Letter(88+dover,y,21,ypb1,ypb2);
  3303.             }
  3304.  
  3305.              Letter(96+dover,y,p_e>>4,ypb1,ypb2);
  3306.             Letter(104+dover,y,p_eh,ypb1,ypb2);
  3307.             Letter(112+dover,y,p_f>>4,ypb1,ypb2);
  3308.             Letter(120+dover,y,p_fh,ypb1,ypb2);
  3309.  
  3310.             }// Track
  3311.             }// Line!=0
  3312.         else
  3313.         {y+=8;}
  3314.  
  3315.         y+=8;
  3316.         }// Line
  3317.         else
  3318.         {
  3319.         Letter(0,y,20,0,7);
  3320.         Letter(8,y,20,0,7);
  3321.         
  3322.         int tvc=24;
  3323.         for(int tvcc=0;tvcc<tvisiblecolums;tvcc++)
  3324.         {
  3325.         Letter(tvc,y,22,0,0);
  3326.         tvc+=118;
  3327.         }
  3328.  
  3329.         y+=8;
  3330.         }
  3331.         S->setBKColor(0,0,0);
  3332.         }
  3333.  
  3334. }
  3335.  
  3336. void Actupated(int modac)
  3337. {
  3338.  
  3339. if (is_editing>1)is_editing=0;
  3340. int nlines=patternLines[pSequence[cPosition]];
  3341.  
  3342. if (ped_line<0)ped_line+=nlines;
  3343. if (ped_line>=nlines)ped_line-=nlines;
  3344. if (ped_row>10){ped_row=0;ped_track++;}
  3345. if (ped_row<0){ped_row=10;ped_track--;}
  3346. if (ped_track>Songtracks-1){ped_track=0;gui_track=0;modac=0;}
  3347. if (ped_track<0){ped_track=Songtracks-1;gui_track=Songtracks-(visiblecolums+1);if(gui_track<0)gui_track=0;modac=0;}
  3348. if (ped_track>=gui_track+visiblecolums){gui_track++;modac=0;}
  3349. if (ped_track<gui_track){gui_track--;modac=0;}
  3350.  
  3351. draw_pated(pSequence[cPosition],gui_track,ped_line,ped_track,ped_row);
  3352.  
  3353. if (is_editing)
  3354. Letter(2,186,27,0,0);
  3355. else
  3356. Letter(2,186,28,0,0);
  3357.  
  3358. draw_pated2(pSequence[cPosition],gui_track,ped_line,ped_track,ped_row);
  3359.  
  3360. }
  3361.  
  3362. void draw_pated2(int pattern,int track, int line, int petrack, int row)
  3363. {
  3364. S->endDraw();
  3365. int ypb1;
  3366. int ypb2;
  3367. int offset_t;
  3368. int dover=0;
  3369.  
  3370.         Letter(0,YVIEW,line>>4,53,68);
  3371.         Letter(8,YVIEW,line&0xf,53,68);
  3372.  
  3373.         int tvisiblecolums=visiblecolums;
  3374.         
  3375.         if (tvisiblecolums>Songtracks)
  3376.             tvisiblecolums=Songtracks;
  3377.  
  3378.         for (int tracky=0;tracky<tvisiblecolums;tracky++)
  3379.             {
  3380.             dover=tracky*118;
  3381.     
  3382.             char tri=track+tracky;
  3383.  
  3384.             if (tri>=block_start_track && tri<=block_end_track && line>=block_start && line<=block_end){ypb1=87;ypb2=102;}else{ypb1=53;ypb2=68;}
  3385.  
  3386.             offset_t=line*96+tri*6+pattern*12288;
  3387.  
  3388.             unsigned char p_a=*(RawPatterns+offset_t);
  3389.             unsigned char p_b=*(RawPatterns+offset_t+1);
  3390.             unsigned char p_bh=p_b&0xf;
  3391.             unsigned char p_c=*(RawPatterns+offset_t+2);
  3392.             unsigned char p_ch=p_c&0xf;
  3393.             unsigned char p_d=*(RawPatterns+offset_t+3);
  3394.             unsigned char p_dh=p_d&0xf;
  3395.             unsigned char p_e=*(RawPatterns+offset_t+4);
  3396.             unsigned char p_eh=p_e&0xf;
  3397.             unsigned char p_f=*(RawPatterns+offset_t+5);
  3398.             unsigned char p_fh=p_f&0xf;
  3399.             
  3400.             // Note
  3401.  
  3402.             if(row==0 && tri==petrack)
  3403.             blitnote(24+dover,YVIEW,p_a,70,85);
  3404.             else
  3405.             blitnote(24+dover,YVIEW,p_a,ypb1,ypb2);
  3406.  
  3407.             // Instrument
  3408.  
  3409.             if(row==1 && tri==petrack)
  3410.             {
  3411.                 if(p_b!=255)
  3412.                 Letter(48+dover,YVIEW,p_b>>4,70,85);
  3413.                 else
  3414.                 Letter(48+dover,YVIEW,21,70,85);
  3415.             }
  3416.             else
  3417.             {
  3418.                 if(p_b!=255)
  3419.                 Letter(48+dover,YVIEW,p_b>>4,ypb1,ypb2);
  3420.                 else
  3421.                 Letter(48+dover,YVIEW,21,ypb1,ypb2);
  3422.             }
  3423.             
  3424.             if(row==2 && tri==petrack)
  3425.             {
  3426.                 if(p_b!=255)
  3427.                 Letter(56+dover,YVIEW,p_bh,70,85);
  3428.                 else
  3429.                 Letter(56+dover,YVIEW,21,70,85);
  3430.             }
  3431.             else
  3432.             {
  3433.                 if(p_b!=255)
  3434.                 Letter(56+dover,YVIEW,p_bh,ypb1,ypb2);
  3435.                 else
  3436.                 Letter(56+dover,YVIEW,21,ypb1,ypb2);
  3437.             }
  3438.  
  3439.             // Volume
  3440.  
  3441.             if(row==3 && tri==petrack)
  3442.             {
  3443.                 if(p_c!=255)
  3444.                 Letter(64+dover,YVIEW,p_c>>4,70,85);
  3445.                 else
  3446.                 Letter(64+dover,YVIEW,21,70,85);
  3447.             }
  3448.             else
  3449.             {
  3450.                 if(p_c!=255)
  3451.                 Letter(64+dover,YVIEW,p_c>>4,ypb1,ypb2);
  3452.                 else
  3453.                 Letter(64+dover,YVIEW,21,ypb1,ypb2);
  3454.             }
  3455.             
  3456.             if(row==4 && tri==petrack)
  3457.             {
  3458.                 if(p_c!=255)
  3459.                 Letter(72+dover,YVIEW,p_ch,70,85);
  3460.                 else
  3461.                 Letter(72+dover,YVIEW,21,70,85);
  3462.             }
  3463.             else
  3464.             {
  3465.                 if(p_c!=255)
  3466.                 Letter(72+dover,YVIEW,p_ch,ypb1,ypb2);
  3467.                 else
  3468.                 Letter(72+dover,YVIEW,21,ypb1,ypb2);
  3469.             }
  3470.  
  3471.             // Panning!
  3472.  
  3473.             if(row==5 && tri==petrack)
  3474.             {
  3475.                 if(p_d!=255)
  3476.                 Letter(80+dover,YVIEW,p_d>>4,70,85);
  3477.                 else
  3478.                 Letter(80+dover,YVIEW,21,70,85);
  3479.             }
  3480.             else
  3481.             {
  3482.                 if(p_d!=255)
  3483.                 Letter(80+dover,YVIEW,p_d>>4,ypb1,ypb2);
  3484.                 else
  3485.                 Letter(80+dover,YVIEW,21,ypb1,ypb2);
  3486.             }
  3487.             
  3488.             if(row==6 && tri==petrack)
  3489.             {
  3490.                 if(p_d!=255)
  3491.                 Letter(88+dover,YVIEW,p_dh,70,85);
  3492.                 else
  3493.                 Letter(88+dover,YVIEW,21,70,85);
  3494.             }
  3495.             else
  3496.             {
  3497.                 if(p_d!=255)
  3498.                 Letter(88+dover,YVIEW,p_dh,ypb1,ypb2);
  3499.                 else
  3500.                 Letter(88+dover,YVIEW,21,ypb1,ypb2);
  3501.             }
  3502.  
  3503.             if(row==7 && tri==petrack)
  3504.             Letter(96+dover,YVIEW,p_e>>4,70,85);
  3505.             else
  3506.             Letter(96+dover,YVIEW,p_e>>4,ypb1,ypb2);
  3507.             
  3508.             if(row==8 && tri==petrack)
  3509.             Letter(104+dover,YVIEW,p_eh,70,85);
  3510.             else
  3511.             Letter(104+dover,YVIEW,p_eh,ypb1,ypb2);
  3512.             
  3513.             if(row==9 && tri==petrack)
  3514.             Letter(112+dover,YVIEW,p_f>>4,70,85);
  3515.             else
  3516.             Letter(112+dover,YVIEW,p_f>>4,ypb1,ypb2);
  3517.             
  3518.             if(row==10 && tri==petrack)
  3519.             Letter(120+dover,YVIEW,p_fh,70,85);
  3520.             else
  3521.             Letter(120+dover,YVIEW,p_fh,ypb1,ypb2);
  3522.             
  3523.             if(sr_isrecording)
  3524.             {
  3525.             if (liveparam>0 && ped_track==tri && Songplaying)
  3526.             {
  3527.                 if (livevalue<0)livevalue=0;
  3528.                 if (livevalue>255)livevalue=255;
  3529.                 
  3530.                 switch(liveparam){
  3531.                 case 1:
  3532.                 *(RawPatterns+offset_t+4)=8;
  3533.                 *(RawPatterns+offset_t+5)=livevalue;
  3534.                 break;
  3535.                 case 2:
  3536.                 *(RawPatterns+offset_t+4)=20;
  3537.                 *(RawPatterns+offset_t+5)=livevalue;
  3538.                 break;
  3539.                 case 3:
  3540.                 *(RawPatterns+offset_t+4)=17;
  3541.                 *(RawPatterns+offset_t+5)=livevalue;
  3542.                 break;
  3543.                 case 4:
  3544.                 *(RawPatterns+offset_t+4)=18;
  3545.                 *(RawPatterns+offset_t+5)=livevalue;
  3546.                 break;
  3547.                 case 5:
  3548.                 *(RawPatterns+offset_t+4)=19;
  3549.                 *(RawPatterns+offset_t+5)=livevalue;
  3550.                 break;
  3551.                 case 6:
  3552.                 if(livevalue>128)livevalue=128;
  3553.                 *(RawPatterns+offset_t+3)=livevalue;
  3554.                 break;
  3555.                 case 7:
  3556.                 *(RawPatterns+offset_t+4)=51;
  3557.                 *(RawPatterns+offset_t+5)=livevalue;
  3558.                 break;
  3559.                 case 8:
  3560.                 *(RawPatterns+offset_t+4)=52;
  3561.                 *(RawPatterns+offset_t+5)=livevalue;
  3562.                 break;
  3563.                 case 9:
  3564.                 *(RawPatterns+offset_t+4)=53;
  3565.                 *(RawPatterns+offset_t+5)=livevalue;
  3566.                 break;
  3567.                 case 10:
  3568.                 *(RawPatterns+offset_t+4)=54;
  3569.                 *(RawPatterns+offset_t+5)=livevalue;
  3570.                 break;
  3571.                 case 11:
  3572.                 *(RawPatterns+offset_t+4)=55;
  3573.                 *(RawPatterns+offset_t+5)=livevalue;
  3574.                 break;
  3575.                 case 12:
  3576.                 *(RawPatterns+offset_t+4)=56;
  3577.                 *(RawPatterns+offset_t+5)=livevalue;
  3578.                 break;
  3579.                 case 13:
  3580.                 *(RawPatterns+offset_t+4)=57;
  3581.                 *(RawPatterns+offset_t+5)=livevalue;
  3582.                 break;
  3583.                 case 14:
  3584.                 *(RawPatterns+offset_t+4)=58;
  3585.                 *(RawPatterns+offset_t+5)=livevalue;
  3586.                 break;
  3587.                 
  3588.                 }// Close switch
  3589.                 liveparam=0;
  3590.             }// Close liveparam updated
  3591.         }// Close is recording
  3592.   }
  3593. }
  3594.  
  3595. void Actualize_Patterned(void)
  3596. {
  3597. if (ped_pattad<0)ped_pattad=16;
  3598. if (ped_pattad>16)ped_pattad=0;
  3599. if (ped_patoct<0)ped_patoct=0;
  3600. if (ped_patoct>8)ped_patoct=8;
  3601. if (ped_patsam<0)ped_patsam=127;
  3602. if (ped_patsam>127)ped_patsam=0;
  3603.  
  3604. char tcp[30];
  3605. sprintf(tcp,"%s_",nameins[ped_patsam]);
  3606.  
  3607. if (snamesel==2)
  3608. guiDial(90,134,166,16,tcp,100);
  3609. else
  3610. guiDial(90,134,166,16,nameins[ped_patsam],120);
  3611.  
  3612. valuer_box2(90,152,ped_pattad);
  3613. valuer_box(258,152,ped_patoct);
  3614. valuer_box(258,134,ped_patsam);
  3615. }
  3616.  
  3617. // Main Player Routine ---------------------------------------------
  3618.  
  3619. void Sp_Player(void)
  3620. {
  3621.     if(Songplaying)
  3622.     {
  3623.         if (PosInTick==0)
  3624.         {
  3625.             Subicounter=0;
  3626.             
  3627.             Patbreak=127;
  3628.  
  3629.             for (int ct=0;ct<Songtracks;ct++)
  3630.             {
  3631.                 int efactor=ct*6+ped_line*96+pSequence[cPosition]*12288;
  3632.                 
  3633.                 pl_note=*(RawPatterns+efactor);
  3634.                 pl_sample=*(RawPatterns+efactor+1);    
  3635.                 pl_vol_row=*(RawPatterns+efactor+2);
  3636.                 pl_pan_row=*(RawPatterns+efactor+3);
  3637.                 pl_eff_row=*(RawPatterns+efactor+4);
  3638.                 pl_dat_row=*(RawPatterns+efactor+5);
  3639.             
  3640.                 if (pl_vol_row<=64)sp_Tvol[ct]=(float)pl_vol_row*0.015625f; // Setting volume.
  3641.                 if (pl_eff_row==3)sp_Tvol[ct]=(float)pl_dat_row*0.0039062f; // Setting volume.
  3642.                 if (pl_pan_row<=128)
  3643.                 {
  3644.                     TPan[ct]=(float)pl_pan_row*0.0078125f; 
  3645.                     ComputeStereo(ct);
  3646.                 }
  3647.  
  3648.                 live303(pl_eff_row,pl_dat_row);
  3649.                 if(pl_eff_row==49){track3031=ct;Fire303(pl_dat_row,0);}
  3650.                 if(pl_eff_row==50){track3032=ct;Fire303(pl_dat_row,1);}
  3651.             
  3652.                 /* MidiController commands */
  3653.                 if (pl_pan_row==144 && c_midiout!=-1 && pl_eff_row<128)
  3654.                 midiOutShortMsg(midiout_handle, (176+TRACKMIDICHANNEL[ct]) | (pl_eff_row << 8) | (pl_dat_row << 16));
  3655.                 
  3656.                 if (pl_eff_row==128 && c_midiout!=-1 && pl_dat_row<128)
  3657.                 midiOutShortMsg(midiout_handle, (176+TRACKMIDICHANNEL[ct]) | (0 << 8) | (pl_dat_row << 16));
  3658.                 
  3659.                 if (pl_eff_row==13 && pl_dat_row<64)Patbreak=pl_dat_row;
  3660.                 
  3661.                 if (pl_note<120)
  3662.                 {
  3663.             
  3664.                 int toffset=0;
  3665.                 glide=0;
  3666.                 if (pl_eff_row==9)toffset=pl_dat_row;
  3667.                 else if (pl_eff_row==5)glide=1;
  3668.     
  3669.                 if (pl_vol_row<=64 || pl_eff_row==3)
  3670.                 Sp_Playwave(ct, (float)pl_note, pl_sample,sp_Tvol[ct],toffset,glide);
  3671.                 else
  3672.                 Sp_Playwave(ct, (float)pl_note, pl_sample,CustomVol[pl_sample],toffset,glide);
  3673.                 }
  3674.                 
  3675.                 if(pl_note==120)
  3676.                 {
  3677.                     // Note OFF on track ct
  3678.                     if (sp_Stage[ct]==1)
  3679.                     sp_Stage[ct]=2;
  3680.                 
  3681.                     Synthesizer[ct].SynthNoteOff();
  3682.                     noteoff303(ct); // 303 Note Off...
  3683.  
  3684.                     if (c_midiout!=-1)
  3685.                     midiOutShortMsg(midiout_handle, (176+ct) | (123 << 8) | (0 << 16));                     
  3686.                 }
  3687.  
  3688.             }// For loop
  3689.             Go303();
  3690.             
  3691.             }// Pos in tick == 0
  3692.  
  3693.             if (!SubCounter)DoEffects();
  3694.             
  3695.             SubCounter++;
  3696.             
  3697.             if (SubCounter>SamplesPerSub-1){SubCounter=0;Subicounter++;}
  3698.             
  3699.             PosInTick++;
  3700.             if (PosInTick>SamplesPerTick+shufflestep)
  3701.             {
  3702.                 shuffleswitch=-shuffleswitch;
  3703.                 
  3704.                 if (shuffleswitch==1)
  3705.                 shufflestep=-((SamplesPerTick*shuffle)/200);
  3706.                 else
  3707.                 shufflestep=(SamplesPerTick*shuffle)/200;
  3708.                 SubCounter=0;
  3709.                 PosInTick=0;
  3710.  
  3711.                 if (Patbreak>63)
  3712.                 {ped_line++;}
  3713.                 else{
  3714.                 ped_line=Patbreak;
  3715.                 cPosition++;
  3716.                 if (cPosition>=sLength)cPosition=0;
  3717.                 }
  3718.  
  3719.                 if (ped_line==patternLines[pSequence[cPosition]])
  3720.                 {
  3721.                     ped_line=0;
  3722.  
  3723.                     if (!plx)cPosition++;
  3724.                     if (cPosition>=sLength)cPosition=0;
  3725.                 }
  3726.             }
  3727.         }
  3728.             
  3729.     left_float=0;
  3730.     right_float=0;
  3731.     delay_left_final=1.0f;
  3732.     delay_right_final=1.0f;
  3733.  
  3734.     for (char c=0;c<Songtracks;c++)
  3735.     {
  3736.     grown=false;
  3737.     currsygnal=0;
  3738.     currsygnal2=0;
  3739.     bool gotsome=false;
  3740.     
  3741.     if (sp_Stage[c]==2)
  3742.         {
  3743.         // Note Stop
  3744.             sp_Tvol[c]=0.0f;
  3745.             
  3746.             if (sp_Cvol[c]<0.01)
  3747.                 sp_Stage[c]=0;
  3748.         }
  3749.     
  3750.     if (sp_Stage[c]!=0)
  3751.     {    
  3752.         gotsome=true;
  3753.         if (sp_Cvol[c]>sp_Tvol[c])
  3754.             sp_Cvol[c]-=0.005f;
  3755.         else
  3756.             sp_Cvol[c]+=0.005f;
  3757.         
  3758.         // Interpolation algorithm
  3759.  
  3760.         Currentpointer=sp_Position[c].half.first;
  3761.         res_dec=sp_Position[c].half.last;
  3762.  
  3763.         currsygnal=Resampler.Work(
  3764.             *(Player_WL[c]+Currentpointer-1),
  3765.             *(Player_WL[c]+Currentpointer),
  3766.             *(Player_WL[c]+Currentpointer+1),
  3767.             *(Player_WL[c]+Currentpointer+2),res_dec,Currentpointer,Rns[c])*sp_Cvol[c]*Player_SV[c];
  3768.     
  3769.         if (Player_SC[c]==2)
  3770.         {
  3771.         grown=true;
  3772.         currsygnal2=Resampler.Work(
  3773.             *(Player_WR[c]+Currentpointer-1),
  3774.             *(Player_WR[c]+Currentpointer),
  3775.             *(Player_WR[c]+Currentpointer+1),
  3776.             *(Player_WR[c]+Currentpointer+2),res_dec,Currentpointer,Rns[c])*sp_Cvol[c]*Player_SV[c];
  3777.         }
  3778.         
  3779.         // End of Interpolation algo
  3780.         
  3781.         sp_Position[c].absolu+=Vstep1[c];
  3782.  
  3783.         if (Player_LT[c]==1 && sp_Position[c].half.first>=Player_LE[c])sp_Position[c].half.first-=Player_LL[c];
  3784.         if (Player_LT[c]==0 && sp_Position[c].half.first>=Player_NS[c])sp_Stage[c]=0;
  3785.         
  3786.         }//sp!!0
  3787.         
  3788.         if(track3031==c){currsygnal+=tb303engine[0].tbGetSample();gotsome=true;}
  3789.         if(track3032==c){currsygnal+=tb303engine[1].tbGetSample();gotsome=true;}
  3790.         if (Synthesizer[c].ENV1_STAGE){currsygnal+=Synthesizer[c].SynthGetSample();gotsome=true;}
  3791.  
  3792.         if(gotsome)
  3793.         {
  3794.         if (FType[c]!=4) /* Track filter actived */
  3795.         {
  3796.         float const dfi = TCut[c]-CCut[c];
  3797.         if (dfi<-1.0 || dfi>1.0)
  3798.             CCut[c]+=dfi*ICut[c];
  3799.     
  3800.         if (FType[c]<4){
  3801.         gco=f2i(ApplyLfo(CCut[c]-ramper[c],c));
  3802.         
  3803.         ramper[c]+=Player_FD[c]*gco*0.015625f;
  3804.         
  3805.         coef[0]=coeftab[0][gco][FRez[c]][FType[c]];
  3806.         coef[1]=coeftab[1][gco][FRez[c]][FType[c]];
  3807.         coef[2]=coeftab[2][gco][FRez[c]][FType[c]];
  3808.         coef[3]=coeftab[3][gco][FRez[c]][FType[c]];
  3809.         coef[4]=coeftab[4][gco][FRez[c]][FType[c]];
  3810.         currsygnal=Filter(currsygnal+1,c);
  3811.         }
  3812.         else
  3813.         {
  3814.         float const realcut=ApplyLfo(CCut[c]-ramper[c],c);
  3815.  
  3816.         ramper[c]+=Player_FD[c]*realcut*0.015625f;
  3817.         
  3818.         switch(FType[c])
  3819.         {
  3820.         case 5:
  3821.         currsygnal=filter2p(c,currsygnal+1,realcut,(float)FRez[c]);
  3822.         break;
  3823.         
  3824.         case 6:
  3825.         currsygnal=filter2p(c,currsygnal+1,realcut,(float)FRez[c]);
  3826.         currsygnal=filter2p24d(c,currsygnal+1,realcut,(float)FRez[c]);
  3827.         break;
  3828.         
  3829.         case 7:
  3830.         currsygnal=filter2p(c,currsygnal+1,realcut,(float)FRez[c]);
  3831.         currsygnal2=filter2p24d(c,currsygnal2+1,realcut,(float)FRez[c]);
  3832.         break;
  3833.  
  3834.         case 8:
  3835.         currsygnal=filterRingMod(c,currsygnal,realcut,(float)FRez[c]);
  3836.         break;
  3837.  
  3838.         case 9:
  3839.         currsygnal=filterRingMod(c,currsygnal,realcut,(float)FRez[c]);
  3840.         currsygnal2=filterRingModStereo(c,currsygnal2);
  3841.         break;
  3842.  
  3843.         case 10:
  3844.         currsygnal=filterWater(c,currsygnal,realcut,(float)FRez[c]);
  3845.         break;
  3846.         
  3847.         case 11:
  3848.         currsygnal=filterWater(c,currsygnal,realcut,(float)FRez[c]);
  3849.         currsygnal2=filterWaterStereo(c,currsygnal2,realcut,(float)FRez[c]);
  3850.         break;
  3851.  
  3852.         case 12:
  3853.         currsygnal=filterBellShaped(c,currsygnal,realcut,(float)FRez[c],-15);
  3854.         break;
  3855.  
  3856.         case 13:
  3857.         currsygnal=filterBellShaped(c,currsygnal,realcut,(float)FRez[c],-6);
  3858.         break;
  3859.  
  3860.         case 14:
  3861.         currsygnal=filterBellShaped(c,currsygnal,realcut,(float)FRez[c],6);
  3862.         break;
  3863.         
  3864.         case 15:
  3865.         currsygnal=filterBellShaped(c,currsygnal,realcut,(float)FRez[c],15);
  3866.         break;
  3867.         
  3868.         case 16:
  3869.         currsygnal=filterDelta(c,currsygnal,realcut,(float)FRez[c]);
  3870.         break;
  3871.  
  3872.         case 17:
  3873.         currsygnal=int_filter2p(c,currsygnal,realcut,(float)FRez[c],0.25f);
  3874.         break;
  3875.         
  3876.         case 18:
  3877.         currsygnal=int_filter2p(c,currsygnal,realcut,(float)FRez[c],0.56f);
  3878.         break;
  3879.         
  3880.         case 19:
  3881.         currsygnal=int_filter2p(c,currsygnal,realcut,(float)FRez[c],0.78f);
  3882.         break;
  3883.  
  3884.         case 20:
  3885.         currsygnal=int_filter2p(c,currsygnal,realcut,(float)FRez[c],0.96f);
  3886.         break;
  3887.  
  3888.         case 21:
  3889.         currsygnal=filterhp(c,currsygnal+1,realcut,(float)FRez[c]);
  3890.         break;
  3891.  
  3892.         case 22:
  3893.         currsygnal=filterhp(c,currsygnal+1,realcut,(float)FRez[c]);
  3894.         currsygnal2=filterhp2(c,currsygnal2+1,realcut,(float)FRez[c]);
  3895.         break;
  3896.  
  3897.         case 23:
  3898.         currsygnal=filterhp(c,currsygnal+1,realcut,(float)FRez[c]);
  3899.         currsygnal=filterhp2(c,currsygnal+1,realcut,(float)FRez[c]);
  3900.         break;
  3901.         
  3902.         }//SWITCHCASE [FILTERS]
  3903.     }        
  3904.     }    /* Filter end */
  3905.  
  3906.     
  3907.     if (!grown)currsygnal2=currsygnal;
  3908.  
  3909.     if (Disclap[c]) /* Distortion */
  3910.     {
  3911.     if (currsygnal>DThreshold[c])
  3912.     currsygnal=DClamp[c];
  3913.     else if(currsygnal<-DThreshold[c])
  3914.     currsygnal=-DClamp[c];
  3915.  
  3916.     if (currsygnal2>DThreshold[c])
  3917.     currsygnal2=DClamp[c];
  3918.     else if(currsygnal2<-DThreshold[c])
  3919.     currsygnal2=-DClamp[c];
  3920.     }
  3921.  
  3922.     currsygnal*=LVol[c];
  3923.     currsygnal2*=RVol[c];
  3924.     
  3925.     // 32-Bit HQ Interpolated System Flanger
  3926.  
  3927.     if (FLANGER_ON[c])
  3928.     {
  3929.     FLANGE_LEFTBUFFER[c][FLANGER_OFFSET[c]]=currsygnal*FLANGER_AMOUNT[c]+oldspawn[c]*FLANGER_FEEDBACK[c];
  3930.     FLANGE_RIGHTBUFFER[c][FLANGER_OFFSET[c]]=currsygnal2*FLANGER_AMOUNT[c]+roldspawn[c]*FLANGER_FEEDBACK[c];
  3931.     
  3932.     float const fstep1=(float)pow(2.0,sin(FLANGER_GR[c])*FLANGER_AMPL[c]);
  3933.     float const fstep2=(float)pow(2.0,sin(FLANGER_GR[c]+FLANGER_DEPHASE[c])*FLANGER_AMPL[c]);
  3934.  
  3935.     foff2[c]+=fstep1;
  3936.     foff1[c]+=fstep2;    
  3937.     
  3938.     if (foff2[c]>=16384.0f)foff2[c]=0.0f;
  3939.     if (foff1[c]>=16384.0f)foff1[c]=0.0f;
  3940.     if (foff2[c]<0.0f)foff2[c]=0.0f;
  3941.     if (foff1[c]<0.0f)foff1[c]=0.0f;
  3942.  
  3943.     oldspawn[c]=FLANGE_LEFTBUFFER[c][f2i(foff2[c])]+1.0f;
  3944.     roldspawn[c]=FLANGE_RIGHTBUFFER[c][f2i(foff1[c])]+1.0f;
  3945.     currsygnal+=oldspawn[c];
  3946.     currsygnal2+=roldspawn[c];
  3947.     
  3948.     if (++FLANGER_OFFSET[c]>16383)FLANGER_OFFSET[c]=0;
  3949.     FLANGER_GR[c]+=FLANGER_RATE[c];
  3950.     
  3951.         if (FLANGER_GR[c]>=6.283185f){
  3952.         FLANGER_GR[c]-=6.283185f;
  3953.         foff2[c]=float(FLANGER_OFFSET[c]-FLANGER_DELAY[c]);
  3954.         foff1[c]=float(FLANGER_OFFSET[c]-FLANGER_DELAY[c]);}
  3955.     }
  3956.  
  3957.     if(!TRACKSTATE[c])// Is the track mute or unmute ???
  3958.     {
  3959.  
  3960.     // Dry Send
  3961.  
  3962.     left_float+=currsygnal;
  3963.     right_float+=currsygnal2;
  3964.  
  3965.     // Sending to delay...
  3966.     
  3967.     float const DS=DSend[c];
  3968.  
  3969.     if (DS>0.008f)
  3970.     {
  3971.     delay_left_final+=currsygnal*DS;
  3972.     delay_right_final+=currsygnal2*DS;
  3973.     }
  3974.  
  3975.     // Sending to chorus
  3976.  
  3977.     float const DC=CCoef[c];
  3978.  
  3979.     if (DC>0.008f)
  3980.     {
  3981.     left_chorus+=currsygnal*DC;
  3982.     right_chorus+=currsygnal2*DC;
  3983.     }
  3984.  
  3985.     }//Close trackstate
  3986.     }//Gotsomething?
  3987.     }// Fortracker
  3988.  
  3989. }
  3990.  
  3991. void Sp_Playwave(int channel, float note, int sample, float vol, unsigned int offset, int glide)
  3992. {
  3993.     FADEMODE[channel]=0;
  3994.     
  3995.     if(sample==255)
  3996.     {
  3997.         sample=sp_channelsample[channel];
  3998.         vol=sp_Tvol[channel];
  3999.     }
  4000.  
  4001.     if (SACTIVE[cPosition][channel])
  4002.     {
  4003.     char split=0;
  4004.     int mnote=int(note);
  4005.     
  4006.     if (Synthprg[sample])
  4007.     {
  4008.     Synthesizer[channel].SynthChangeParameters(PARASynth[sample]);
  4009.     Synthesizer[channel].SynthNoteOn(note-48,vol);
  4010.     }
  4011.  
  4012.     for(char revo=0;revo<16;revo++)
  4013.     {
  4014.     if (note>=Basenote[sample][revo] && SampleType[sample][revo]!=0)
  4015.     split=revo;
  4016.     }
  4017.  
  4018.     note-=Basenote[sample][split];
  4019.     note+=float((float)Finetune[sample][split]*0.0078125f);
  4020.     
  4021.     if (sample!=sp_channelsample[channel] || !sp_Stage[channel])
  4022.         glide=0;
  4023.  
  4024.     if (SampleType[sample][split])
  4025.     {
  4026.     sp_Stage[channel]=1;
  4027.  
  4028.     if (!offset)
  4029.         sp_Cvol[channel]=vol;
  4030.     else
  4031.         sp_Cvol[channel]=0;
  4032.     
  4033.     sp_Tvol[channel]=vol;
  4034.     
  4035.     if(beatsync[sample])
  4036.     {
  4037.     double spreadnote=(double)(SampleNumSamples[sample][split])/((double)beatlines[sample]*(double)SamplesPerTick);
  4038.     spreadnote*=4294967296.0f;
  4039.     Vstep1[channel]=spreadnote;
  4040.     sp_Step[channel]=spreadnote;
  4041.     }
  4042.     else
  4043.     {
  4044.     double spreadnote=(double)pow(2.0f,note/12.0f);
  4045.     spreadnote*=4294967296.0f;
  4046.     
  4047.     if(glide)
  4048.     sp_Step[channel]=spreadnote;
  4049.     else
  4050.     {
  4051.     Vstep1[channel]=spreadnote;
  4052.     sp_Step[channel]=spreadnote;}
  4053.     }
  4054.     
  4055.     sp_channelsample[channel]=sample;
  4056.     sp_split[channel]=split;
  4057.     
  4058.     // Player Pointer Assignment
  4059.  
  4060.     Player_LS[channel]=LoopStart[sample][split];
  4061.     Player_LE[channel]=LoopEnd[sample][split];
  4062.     
  4063.     Player_LL[channel]=Player_LE[channel]-Player_LS[channel];
  4064.     
  4065.     Player_NS[channel]=SampleNumSamples[sample][split]-2;
  4066.     Rns[channel]=SampleNumSamples[sample][split];
  4067.     Player_SV[channel]=SampleVol[sample][split];
  4068.     Player_LT[channel]=LoopType[sample][split];
  4069.     Player_SC[channel]=SampleChannels[sample][split];
  4070.     Player_FD[channel]=FDecay[sample][split];
  4071.     Player_WL[channel]=RawSamples[sample][0][split];
  4072.     
  4073.     if(SampleChannels[sample][split]==2)
  4074.     Player_WR[channel]=RawSamples[sample][1][split];
  4075.     
  4076.     if (!glide)
  4077.     {
  4078.     if(!AMIMODE)
  4079.     sp_Position[channel].half.first=(offset*SampleNumSamples[sample][split])>>8;
  4080.     else
  4081.     sp_Position[channel].half.first=offset<<8;
  4082.  
  4083.     if(sp_Position[channel].half.first>=SampleNumSamples[sample][split])sp_Stage[channel]=0;
  4084.         
  4085.     ramper[channel]=0;
  4086.     }
  4087.  
  4088.     }
  4089.  
  4090.     if(TRACKSTATE[channel]==0 && c_midiout!=-1 && Midiprg[sample]!=-1)
  4091.     {
  4092.     /* haz esta linea si se cambia el programa midi */
  4093.     if (LastProgram[TRACKMIDICHANNEL[channel]]!=Midiprg[sample])
  4094.     {
  4095.     midiOutShortMsg(midiout_handle, (192+TRACKMIDICHANNEL[channel]) | (Midiprg[sample] << 8) | (127 << 16)); 
  4096.     LastProgram[TRACKMIDICHANNEL[channel]]=Midiprg[sample];
  4097.     }
  4098.     /* suelta la nota */
  4099.     float veloc=vol*mas_vol;
  4100.     midiOutShortMsg(midiout_handle, (144+TRACKMIDICHANNEL[channel]) | (mnote << 8) | (f2i(veloc*255)<< 16));
  4101.     }
  4102.     }
  4103. }
  4104.  
  4105. void SongPlay(void)
  4106. {
  4107. SongStop();
  4108. clipc=0;
  4109. liveparam=0;
  4110. livevalue=0;
  4111. player_pos=-1;
  4112. shufflestep=shuffle;
  4113. shuffleswitch=-1;
  4114.  
  4115. if (plx==0)
  4116. {
  4117. guiDial(8,60,80,16,"Playing Song",100);
  4118. mess_box("Playing song...");
  4119. }
  4120. else
  4121. {
  4122. guiDial(8,60,80,16,"Playing Pattern",100);
  4123. mess_box("Playing pattern...");
  4124. }
  4125. SamplesPerTick=(int)((60 * SamplesPerSec) / (BeatsPerMin * TicksPerBeat));  
  4126. PosInTick=0; 
  4127. SamplesPerSub=SamplesPerTick/6;
  4128. ped_line=0;
  4129. Songplaying=1;
  4130. for (int spl=0;spl<MAX_TRACKS;spl++)
  4131. CCoef[spl]=float((float)CSend[spl]/127.0);
  4132.  
  4133. if (shuffleswitch==1)
  4134. shufflestep=-((SamplesPerTick*shuffle)/200);
  4135. else
  4136. shufflestep=(SamplesPerTick*shuffle)/200;
  4137. }
  4138.  
  4139. void StartRec(void)
  4140. {
  4141. liveparam=0;
  4142. livevalue=0;
  4143. if (sr_isrecording)
  4144. guiDial(8,78,80,16,"Slider Rec: ON",100);
  4145. else
  4146. guiDial(8,78,80,16,"Slider Rec: OFF",200);
  4147. }
  4148.  
  4149. void SongStop(void)
  4150. {
  4151. guiDial(8,60,80,16,"Play Sng/Pttrn",200);
  4152. mess_box("Ready...");
  4153. Songplaying=0;
  4154. tb303engine[0].tbPattern=255;
  4155. tb303engine[0].tbLine=255;
  4156. tb303engine[1].tbPattern=255;
  4157. tb303engine[1].tbLine=255;
  4158. track3031=255;
  4159. track3032=255;
  4160.  
  4161. MidiAllNotesOff();
  4162.  
  4163. for (int stopper=0;stopper<MAX_TRACKS;stopper++)
  4164. {sp_Stage[stopper]=0;Synthesizer[stopper].SynthNoteOff();}
  4165.     
  4166. }
  4167.  
  4168. void Iniplayer(void)
  4169. {
  4170. SamplesPerTick=(int)((60 * SamplesPerSec) / (BeatsPerMin * TicksPerBeat));  
  4171. Feedback=0.5f;
  4172. rx1=rx2=ry1=ry2=rx12=rx22=ry12=ry22=0.0f;
  4173. MidiReset();
  4174. allPassInit(c_threshold);
  4175.  
  4176. for (int ini=0;ini<MAX_TRACKS;ini++)
  4177.     {
  4178.     FADEMODE[ini]=0;
  4179.     FADECOEF[ini]=0.0f;
  4180.     Synthesizer[ini].SynthReset();
  4181.     Player_FD[ini]=0.0f;
  4182.     ResetFilters(ini);
  4183.     sp_channelsample[ini]=0;
  4184.     sp_split[ini]=0;
  4185.  
  4186.     TRACKMIDICHANNEL[ini]=ini;
  4187.     TRACKSTATE[ini]=0;
  4188.     oldspawn[ini]=0.0f;
  4189.     roldspawn[ini]=0.0f;
  4190.     LFO_ON[ini]=0;
  4191.     LFORATE[ini]=0.0001f;
  4192.     LFOAMPL[ini]=0;
  4193.     LFOGR[ini]=0;
  4194.     FLANGER_AMOUNT[ini]=-0.8f;
  4195.     FLANGER_DEPHASE[ini]=0.0174532f;
  4196.     FLANGER_ON[ini]=0;
  4197.     FLANGER_RATE[ini]=0.0068125f/57.29578f;
  4198.     FLANGER_AMPL[ini]=0.0f;
  4199.     FLANGER_GR[ini]=0;
  4200.     FLANGER_FEEDBACK[ini]=-0.51f;
  4201.     FLANGER_DELAY[ini]=176;
  4202.     FLANGER_OFFSET[ini]=176;
  4203.     foff2[ini]=0.0f;
  4204.     foff1[ini]=0.0f;
  4205.     for (int ini2=0;ini2<16400;ini2++)
  4206.     {
  4207.     FLANGE_LEFTBUFFER[ini][ini2]=0.0f;
  4208.     FLANGE_RIGHTBUFFER[ini][ini2]=0.0f;
  4209.     }
  4210.  
  4211.     sp_Cvol[ini]=0.0f;
  4212.     sp_Tvol[ini]=0.0f;
  4213.     DSend[ini]=0.0;
  4214.     CSend[ini]=0;
  4215.     Vstep1[ini]=0;
  4216.     glidestep[ini]=0;
  4217.     TPan[ini]=0.5f;
  4218.     ComputeStereo(ini);
  4219.     sp_Position[ini].absolu=0;
  4220.     CCut[ini]=126.0;
  4221.     TCut[ini]=126.0;
  4222.     ICut[ini]=0.0039062f;
  4223.     FType[ini]=4;
  4224.     FRez[ini]=64;
  4225.     DThreshold[ini]=65535;
  4226.     Disclap[ini]=false;
  4227.     Dispan[ini]=false;
  4228.  
  4229.     DClamp[ini]=65535;
  4230.     CCoef[ini]=0;    
  4231.     }
  4232.  
  4233.     for (int dini=0;dini<131071;dini++)
  4234.     {
  4235.     lbuff_chorus[dini]=0;
  4236.     rbuff_chorus[dini]=0;
  4237.     }
  4238.  
  4239. for (int cutt=0;cutt<128;cutt++)
  4240. {
  4241. for (int rezz=0;rezz<128;rezz++)
  4242. {
  4243. for (int typp=0;typp<4;typp++)
  4244. {
  4245. ComputeCoefs(cutt,rezz,typp);
  4246. coeftab[0][cutt][rezz][typp]=coef[0];        
  4247. coeftab[1][cutt][rezz][typp]=coef[1];
  4248. coeftab[2][cutt][rezz][typp]=coef[2];
  4249. coeftab[3][cutt][rezz][typp]=coef[3];
  4250. coeftab[4][cutt][rezz][typp]=coef[4];
  4251. }
  4252. }
  4253. }
  4254.  
  4255. }
  4256.  
  4257. void Actualize_Master(char gode)
  4258. {
  4259.  
  4260. if (gode==0 || gode==1)
  4261. {
  4262. if (BeatsPerMin<32)BeatsPerMin=32;
  4263. if (BeatsPerMin>255)BeatsPerMin=255;
  4264. valuer_box(324,78,BeatsPerMin);
  4265. }
  4266.  
  4267. if (gode==0 || gode==2)
  4268. {
  4269. if (TicksPerBeat<1)TicksPerBeat=1;
  4270. if (TicksPerBeat>16)TicksPerBeat=16;
  4271. valuer_box(324,96,TicksPerBeat);
  4272. }
  4273.  
  4274. if (gode==0)
  4275. valuer_box2(324,60,Songtracks);
  4276.  
  4277. if (gode==4)
  4278. {
  4279. valuer_box2(324,60,Songtracks);
  4280. S->setColor(0,0,0);
  4281.  
  4282. if(userscreen==4)
  4283. {S->setColor(0,0,0);
  4284. bjbox(257,346,124,86);
  4285. Actualize_Seq_Ed();
  4286. }
  4287.  
  4288. if (userscreen!=8)
  4289. {
  4290. S->endDraw();
  4291. S->copy(FRAMEWORK, 0, 184);
  4292. }
  4293. else
  4294. bjbox(0,186,fsize,248);
  4295.  
  4296. Actupated(0);
  4297. }
  4298.  
  4299. SamplesPerTick=(int)((60 * SamplesPerSec) / (BeatsPerMin * TicksPerBeat));  
  4300. float SamplesPerBeat=(float)SamplesPerSec/(((float)BeatsPerMin*4)/60);
  4301. SamplesPerSub=SamplesPerTick/6;
  4302.  
  4303. if(userscreen==5)Actualize_Master_Ed(3);
  4304. }
  4305.  
  4306. void draw_tracked(void)
  4307. {
  4308. guiDial(112,309,64,16,"Track FX",200);
  4309. guiDial(178,309,64,16,"Midi/CSynth",200);
  4310. guiDial(244,309,64,16,"Master",200);
  4311. guiDial(310,309,64,16,"Sequencer",200);
  4312. guiDial(376,309,64,16,"Disk IO",200);
  4313. guiDial(442,309,64,16,"Track",100);
  4314. guiDial(508,309,64,16,"Instrument",200);
  4315. guiDial(574,309,64,16,"FX Setup",200);
  4316. guiDial(640,309,64,16,"Extend Edit",200);
  4317. guiDial(706,309,64,16,"303",200);
  4318.  
  4319. guiDial2("Track: Properties & Fx Send");
  4320.  
  4321. guiDial3(508,344,60,16,"Track",200);
  4322. guiDial3(570,344,60,16,"Delay Send",200);
  4323. guiDial(508,406,60,16,"Solo Track",200);
  4324. guiDial(508,424,60,16,"Un-mute All",200);
  4325.  
  4326. guiDial3(8,344,224,96,"Analog Filter Emulation",128);
  4327. guiDial3(18,360,56,16,"CutOff Frq.",200);
  4328. guiDial3(18,378,56,16,"Resonance",200);
  4329. guiDial3(18,396,56,16,"Type",200);
  4330. guiDial3(18,414,56,16,"Inertia",200);
  4331.  
  4332. guiDial3(240,344,260,96,"Distorsion/Reverb/Pan",128);
  4333. guiDial3(248,360,56,16,"Threshold",200);
  4334. guiDial3(248,378,56,16,"Clamp",200);
  4335. guiDial3(248,396,56,16,"Reverb",200);
  4336. guiDial3(248,414,56,16,"Pan",200);
  4337. guiDial(456,360,40,16,"Flat2C",200);
  4338. guiDial(456,378,40,16,"Flat2T",200);
  4339. guiDial(456,414,40,16,"Center",200);
  4340. guiDial3(570,388,60,16,"Midi Chnl.",200);
  4341. }
  4342.     
  4343. float Filter( float x, char i)
  4344. {
  4345.         float y;
  4346.         y = coef[0]*x + coef[1]*fx1[i] + coef[2]*fx2[i] + coef[3]*fy1[i] + coef[4]*fy2[i];
  4347.         fy2[i]=fy1[i];
  4348.         fy1[i]=y;
  4349.         fx2[i]=fx1[i];
  4350.         fx1[i]=x;
  4351.         return y;
  4352. }
  4353.  
  4354. float RevFilter(float x)
  4355. {
  4356.         float y=x;
  4357.         return y;
  4358. }
  4359.  
  4360. float RevFilter2(float x)
  4361. {
  4362.  
  4363.         float y=x;
  4364.         return y;
  4365. }
  4366.  
  4367. void ComputeCoefs(int freq, int r, int t)
  4368. {
  4369.     float omega =float (2*PI*Kutoff(freq)/44100);
  4370.     float sn = (float)sin( omega);
  4371.     float cs = (float)cos( omega);
  4372.     float alpha;
  4373.         
  4374.     if( t<2)
  4375.     alpha =float(sn / Reonance( r *(freq+70)/(127.0f+70)));
  4376.     else
  4377.     alpha =float (sn * sinh( Bandwidth( r) * omega/sn));
  4378.  
  4379.         float a0, a1, a2, b0, b1, b2;
  4380.  
  4381.         switch( t)
  4382.         {
  4383.     
  4384.         case 0: // LP
  4385.                 b0 =  (1 - cs)/2;
  4386.                 b1 =   1 - cs;
  4387.                 b2 =  (1 - cs)/2;
  4388.                 a0 =   1 + alpha;
  4389.                 a1 =  -2*cs;
  4390.                 a2 =   1 - alpha;
  4391.                 break;
  4392.         case 1: // HP
  4393.                 b0 =  (1 + cs)/2;
  4394.                 b1 = -(1 + cs);
  4395.                 b2 =  (1 + cs)/2;
  4396.                 a0 =   1 + alpha;
  4397.                 a1 =  -2*cs;
  4398.                 a2 =   1 - alpha;
  4399.                 break;
  4400.         case 2: // BP
  4401.                 b0 =   alpha;
  4402.                 b1 =   0;
  4403.                 b2 =  -alpha;
  4404.                 a0 =   1 + alpha;
  4405.                 a1 =  -2*cs;
  4406.                 a2 =   1 - alpha;
  4407.                 break;
  4408.         case 3: // BR
  4409.                 b0 =   1;
  4410.                 b1 =  -2*cs;
  4411.                 b2 =   1;
  4412.                 a0 =   1 + alpha;
  4413.                 a1 =  -2*cs;
  4414.                 a2 =   1 - alpha;
  4415.                 break;
  4416.         }
  4417.  
  4418.         coef[0] = b0/a0;
  4419.         coef[1] = b1/a0;
  4420.         coef[2] = b2/a0;
  4421.         coef[3] = -a1/a0;
  4422.         coef[4] = -a2/a0;
  4423. }
  4424.     
  4425.  
  4426. float Kutoff( int v)
  4427. {
  4428.         return float(pow( (v+5)/(127.0+5), 1.7)*13000+30);
  4429. }
  4430.  
  4431. float Reonance( float v)
  4432. {
  4433.         return float(pow( v/127.0, 4)*150+0.1);
  4434. }
  4435.  
  4436. float Bandwidth( int v)
  4437. {
  4438.         return float(pow( v/127.0, 4)*4+0.1);
  4439. }
  4440.  
  4441. void Actualize_Track_Ed(char gode)
  4442. {
  4443. if (userscreen==1)
  4444. {
  4445.  
  4446. if (gode==0){
  4447. if (ped_track>MAX_TRACKS-1)ped_track=0;
  4448. if (ped_track<0)ped_track=MAX_TRACKS-1;
  4449. valuer_box(508,362,ped_track);}
  4450.  
  4451. if (gode==0 || gode==1){
  4452. if (TCut[ped_track]<0)TCut[ped_track]=0;
  4453. if (TCut[ped_track]>127)TCut[ped_track]=127;
  4454. Realslider(78,360,(int)TCut[ped_track]);}
  4455.  
  4456. if (gode==0 || gode==2){
  4457. if (FRez[ped_track]<0)FRez[ped_track]=0;
  4458. if (FRez[ped_track]>127)FRez[ped_track]=127;
  4459. Realslider(78,378,FRez[ped_track]);}
  4460.  
  4461. if (gode==0 || gode==3){
  4462. if (ICut[ped_track]>0.0078125f)ICut[ped_track]=0.0078125f;
  4463. if (ICut[ped_track]<0.00006103515625f)ICut[ped_track]=0.00006103515625f;
  4464. Realslider(78,414,f2i(ICut[ped_track]*16384.0f));}
  4465.  
  4466. if (gode==0 || gode==4){
  4467. switch(FType[ped_track]){
  4468. case 0:guiDial(139,396,86,16,"LowPass -12db",200);break;
  4469. case 1:guiDial(139,396,86,16,"HiPass",200);break;
  4470. case 2:guiDial(139,396,86,16,"BandPass",200);break;
  4471. case 3:guiDial(139,396,86,16,"BandReject",200);break;
  4472. case 4:guiDial(139,396,86,16,"Filter Off",200);break;
  4473. case 5:guiDial(139,396,86,16,"LowPass -24db",200);break;
  4474. case 6:guiDial(139,396,86,16,"LowPass -48db",200);break;
  4475. case 7:guiDial(139,396,86,16,"LP-24 [Stereo]",200);break;
  4476. case 8:guiDial(139,396,86,16,"A.Mod. [Mono]",200);break;
  4477. case 9:guiDial(139,396,86,16,"A.Mod. [Stereo]",200);break;
  4478. case 10:guiDial(139,396,86,16,"Single [Mono]",200);break;
  4479. case 11:guiDial(139,396,86,16,"Single [Stereo]",200);break;
  4480. case 12:guiDial(139,396,86,16,"ParaEQ -15db",200);break;
  4481. case 13:guiDial(139,396,86,16,"ParaEQ -6db",200);break;
  4482. case 14:guiDial(139,396,86,16,"ParaEQ +6db",200);break;
  4483. case 15:guiDial(139,396,86,16,"ParaEQ +15db",200);break;
  4484. case 16:guiDial(139,396,86,16,"Custom Delta",200);break;
  4485. case 17:guiDial(139,396,86,16,"Comp.Distort L",200);break;
  4486. case 18:guiDial(139,396,86,16,"Comp.Distort M",200);break;
  4487. case 19:guiDial(139,396,86,16,"Comp.Distort H",200);break;
  4488. case 20:guiDial(139,396,86,16,"Comp.Distort!!",200);break;
  4489. case 21:guiDial(139,396,86,16,"W-HP12[Mono]",200);break;
  4490. case 22:guiDial(139,396,86,16,"W-HP12[Stereo]",200);break;
  4491. case 23:guiDial(139,396,86,16,"W-HP24[Mono]",200);break;
  4492. }
  4493. valuer_box(77,396,FType[ped_track]);
  4494. }
  4495.  
  4496. if (gode==0 || gode==5){
  4497. if (DSend[ped_track]<0)DSend[ped_track]=0;
  4498. if (DSend[ped_track]>1.0)DSend[ped_track]=1.0;
  4499. Realslider(308,396,int(DSend[ped_track]*128.0));}
  4500.  
  4501. if (gode==0 || gode==6){
  4502. if (CSend[ped_track]<0)CSend[ped_track]=0;
  4503. if (CSend[ped_track]>127)CSend[ped_track]=127;
  4504. valuer_box(570,362,CSend[ped_track]);
  4505. CCoef[ped_track]=float((float)CSend[ped_track]/127.0);}
  4506.  
  4507. if (gode==0 || gode==7){
  4508. if (DThreshold[ped_track]<0)DThreshold[ped_track]=0;
  4509. if (DThreshold[ped_track]>65535)DThreshold[ped_track]=65535;
  4510. Realslider(308,360,(int)DThreshold[ped_track]/512);}
  4511.  
  4512. if (gode==0 || gode==8){
  4513. if (DClamp[ped_track]<0)DClamp[ped_track]=0;
  4514. if (DClamp[ped_track]>65535)DClamp[ped_track]=65535;
  4515. Realslider(308,378,(int)DClamp[ped_track]/512);}
  4516.  
  4517. if (gode==0 || gode==9){
  4518. if (TPan[ped_track]<0.0f)TPan[ped_track]=0.0f;
  4519. if (TPan[ped_track]>1.0f)TPan[ped_track]=1.0f;
  4520. ComputeStereo(ped_track);
  4521. Realslider(308,414,f2i(TPan[ped_track]*127.0f));}
  4522.  
  4523. if (gode==0 || gode==10){
  4524. if (TRACKSTATE[ped_track])
  4525. guiDial(508,388,60,16,"Un-Mute",100);
  4526. else
  4527. guiDial(508,388,60,16,"Mute Track",200);}
  4528.  
  4529. if (gode==0 || gode==11){
  4530. if (TRACKMIDICHANNEL[ped_track]>15)TRACKMIDICHANNEL[ped_track]=0;
  4531. if (TRACKMIDICHANNEL[ped_track]<0)TRACKMIDICHANNEL[ped_track]=15;
  4532. valuer_box2(570,406,TRACKMIDICHANNEL[ped_track]+1);}
  4533.  
  4534. if (gode==0 || gode==12)
  4535. {
  4536. if(Disclap[ped_track])
  4537. guiDial(570,424,60,16,"Distort On",100);
  4538. else
  4539. guiDial(570,424,60,16,"Distort Off",200);
  4540. }
  4541.  
  4542. if (trkchan==true)
  4543. {
  4544. Actupated(0);
  4545. trkchan=false;
  4546. }
  4547.     
  4548. }// Userscreen match found
  4549.  
  4550. }
  4551.  
  4552. void Realslider(int x,int y,int val)
  4553. {
  4554. S->setColor(0,192,0);
  4555. bjbox(x+2,y+4,val,12);
  4556.  
  4557. S->setColor(0,128,0);
  4558. S->line(x+2,y+2,x+2+val,y+2);
  4559. S->line(x+2,y+16,x+2+val,y+16);
  4560.  
  4561. guiDial(x+2+val,y+1,13,14,"",240);
  4562.  
  4563. S->setColor(0,0,0);
  4564. bjbox(x+2+val+16,y+2,128-val,16);
  4565. }
  4566.  
  4567. void Realslider2(int x,int y,int val)
  4568. {
  4569. S->setColor(0,192,0);
  4570. bjbox(x+2,y+4,val,12);
  4571.  
  4572. S->setColor(0,128,0);
  4573. S->line(x+2,y+2,x+2+val,y+2);
  4574. S->line(x+2,y+16,x+2+val,y+16);
  4575.  
  4576. guiDial(x+2+val,y+1,13,14,"",240);
  4577.  
  4578. S->setColor(0,0,0);
  4579. bjbox(x+2+val+16,y+2,64-val,16);
  4580. }
  4581.  
  4582. inline int f2i(double d)
  4583. {
  4584.   const double magic = 6755399441055744.0; // 2^51 + 2^52
  4585.   double tmp = (d-0.5) + magic;
  4586.   return *(int*) &tmp;
  4587. }
  4588.  
  4589. void draw_fxed(void)
  4590. {
  4591. guiDial(112,309,64,16,"Track FX",200);
  4592. guiDial(178,309,64,16,"Midi/CSynth",200);
  4593. guiDial(244,309,64,16,"Master",200);
  4594. guiDial(310,309,64,16,"Sequencer",200);
  4595. guiDial(376,309,64,16,"Disk IO",200);
  4596. guiDial(442,309,64,16,"Track",200);
  4597. guiDial(508,309,64,16,"Instrument",200);
  4598. guiDial(574,309,64,16,"FX Setup",100);
  4599. guiDial(640,309,64,16,"Extend Edit",200);
  4600. guiDial(706,309,64,16,"303",200);
  4601.  
  4602. guiDial2("FX: Setup");
  4603. guiDial3(8,344,224,104,"Reverb Setup",128);
  4604. guiDial3(18,360,56,16,"Switch",200);
  4605. guiDial3(18,378,56,16,"Feedback",200);
  4606. guiDial3(18,396,56,16,"Type",200);
  4607. guiDial3(18,414,56,16,"Room Size",200);
  4608. guiDial3(18,432,56,16,"Filter",200);
  4609.  
  4610. guiDial3(240,344,288,96,"Stereo Delay Settings",128);
  4611. guiDial3(248,360,56,16,"L.Delay",200);
  4612. guiDial3(248,378,56,16,"R.Delay",200);
  4613. guiDial3(248,396,56,16,"L.Decay",200);
  4614. guiDial3(248,414,56,16,"R.Decay",200);
  4615. guiDial3(530,344,104,56,"Tick Synchro",128);
  4616. guiDial(540,360,16,16,"x1",200);
  4617. guiDial(540,378,16,16,"x1",200);
  4618. guiDial(558,360,16,16,"x2",200);
  4619. guiDial(558,378,16,16,"x2",200);
  4620. guiDial(576,360,16,16,"x3",200);
  4621. guiDial(576,378,16,16,"x3",200);
  4622. guiDial(594,360,16,16,"x4",200);
  4623. guiDial(594,378,16,16,"x4",200);
  4624. guiDial(612,360,16,16,"x5",200);
  4625. guiDial(612,378,16,16,"x5",200);
  4626. }
  4627.  
  4628. void Actualize_Fx_Ed(char gode)
  4629. {
  4630. if (gode==0 || gode==1){
  4631. if(DelayType<0)DelayType=0;
  4632. if(DelayType>6)DelayType=6;
  4633. switch (DelayType)
  4634. {
  4635. case 0:guiDial3(139,396,86,16,"Room",200);break;
  4636. case 1:guiDial3(139,396,86,16,"Great Hall",200);break;
  4637. case 2:guiDial3(139,396,86,16,"Room 2",200);break;
  4638. case 3:guiDial3(139,396,86,16,"Echoy",200);break;
  4639. case 4:guiDial3(139,396,86,16,"1Comb",200);break;
  4640. case 5:guiDial3(139,396,86,16,"Room2",200);break;
  4641. case 6:guiDial3(139,396,86,16,"Hall3",200);break;
  4642.  
  4643. default:guiDial3(139,396,86,16,"Not Defined",200);break;
  4644. }
  4645.  
  4646. if (gode)Initreverb();
  4647. valuer_box(77,396,DelayType);
  4648. }
  4649.  
  4650. if (gode==0 || gode==2)
  4651. Realslider(78,378,f2i(Feedback*127.0));
  4652.  
  4653. if (gode==0 || gode==3){
  4654. if (lchorus_delay>22100)lchorus_delay=22100;
  4655. if (lchorus_delay<1)lchorus_delay=1;
  4656. if(gode==3){lchorus_counter=44100;lchorus_counter2=44100-lchorus_delay;}
  4657. Realslider(308,360,lchorus_delay/175);
  4658. outlong(458,360,(lchorus_delay*1000)/44100,2);}
  4659.  
  4660. if (gode==0 || gode==4){
  4661. if (rchorus_delay>22100)rchorus_delay=22100;
  4662. if (rchorus_delay<1)rchorus_delay=1;
  4663. if(gode==4){rchorus_counter=44100;rchorus_counter2=44100-rchorus_delay;}
  4664. Realslider(308,378,rchorus_delay/175);
  4665. outlong(458,378,(rchorus_delay*1000)/44100,2);}
  4666.  
  4667. if (gode==0 || gode==5){
  4668. if (lchorus_feedback>0.95f)lchorus_feedback=0.95f;
  4669. if (lchorus_feedback<0)lchorus_feedback=0;
  4670. Realslider(308,396,f2i(lchorus_feedback*127));
  4671. outlong(458,396,f2i(lchorus_feedback*100),1);}
  4672.  
  4673. if (gode==0 || gode==6){
  4674. if (rchorus_feedback>0.95f)rchorus_feedback=0.95f;
  4675. if (rchorus_feedback<0)rchorus_feedback=0;
  4676. Realslider(308,414,f2i(rchorus_feedback*127));
  4677. outlong(458,414,f2i(rchorus_feedback*100),1);}
  4678.  
  4679. if (gode==0 || gode==7)
  4680. {
  4681. if (c_threshold<10)c_threshold=10;
  4682. if (c_threshold>127)c_threshold=127;
  4683. Realslider(78,414,c_threshold);
  4684. allPassInit(c_threshold);
  4685. }
  4686.  
  4687. if (gode==0 || gode==8)
  4688. {
  4689. if(compressor==0)
  4690. {
  4691. guiDial(78,360,32,16,"On",200);
  4692. guiDial(112,360,32,16,"Off",100);
  4693. }
  4694. else
  4695. {
  4696. guiDial(78,360,32,16,"On",100);
  4697. guiDial(112,360,32,16,"Off",200);
  4698. }
  4699. }
  4700.  
  4701. if (gode==0 || gode==9)
  4702. {
  4703. if (REVERBFILTER<0.05f)REVERBFILTER=0.05f;
  4704. if (REVERBFILTER>0.99f)REVERBFILTER=0.99f;
  4705. Realslider(78,432,f2i(REVERBFILTER*128.0f));
  4706. }
  4707. }
  4708.  
  4709. void draw_sampleed(void)
  4710. {
  4711. guiDial(112,309,64,16,"Track FX",200);
  4712. guiDial(178,309,64,16,"Midi/CSynth",200);
  4713. guiDial(244,309,64,16,"Master",200);
  4714. guiDial(310,309,64,16,"Sequencer",200);
  4715. guiDial(376,309,64,16,"Disk IO",200);
  4716. guiDial(442,309,64,16,"Track",200);
  4717. guiDial(508,309,64,16,"Instrument",100);
  4718. guiDial(574,309,64,16,"FX Setup",200);
  4719. guiDial(640,309,64,16,"Extend Edit",200);
  4720. guiDial(706,309,64,16,"303",200);
  4721.  
  4722. switch(seditor){
  4723. case 0:
  4724. guiDial2("Instrument Editor [Sampler]");
  4725. guiDial(268,346,88,16,"Loop Fine Editor",200);
  4726. guiDial(268,364,88,16,"Export .Wav File",200);
  4727.  
  4728. guiDial3(382,409,42,16,"Amplify",200);
  4729. guiDial3(382,427,42,16,"Tune",200);
  4730.  
  4731. guiDial3(382,337,64,16,"Length",200);
  4732. guiDial3(382,355,64,16,"Loop Start",200);
  4733. guiDial3(382,373,64,16,"Loop End",200);
  4734. guiDial3(382,391,64,16,"Loop Play",200);
  4735. guiDial3(8,408,42,16,"F.Decay",200);
  4736. guiDial3(8,426,42,16,"Def.Vol",200);
  4737. guiDial3(510,337,58,16,"Split",200);
  4738. guiDial3(510,355,58,16,"BaseNote",200);
  4739. guiDial3(510,373,58,16,"Midi Prg.",200);
  4740. guiDial3(510,391,58,16,"Synth Prg.",200);
  4741. guiDial3(8,372,134,16,"Loop Tempo Auto Synchro",200);
  4742. guiDial3(8,390,134,16,"Synchro Length (In Lines)",200);
  4743. break;
  4744.  
  4745. case 1:
  4746. guiDial2("Instrument Editor [Loop Editor]");
  4747. guiDial3(424,355,58,16,"LS. Value",200);
  4748. guiDial3(424,373,58,16,"LE. Value",200);
  4749. guiDial(424,391,58,16,"Exit Editor",200);
  4750. guiDial3(20,350,56,16,"Loop Start",200);
  4751. guiDial(78,350,16,16,"<<",250);
  4752. guiDial(96,350,16,16,"<",250);
  4753. guiDial(176,350,16,16,">",250);
  4754. guiDial(194,350,16,16,">>",250);
  4755. guiDial3(220,350,56,16,"Loop End",200);
  4756. guiDial(278,350,16,16,"<<",250);
  4757. guiDial(296,350,16,16,"<",250);
  4758. guiDial(376,350,16,16,">",250);
  4759. guiDial(394,350,16,16,">>",250);
  4760.  
  4761. break;
  4762. }//Switch Sampler Screen
  4763.  
  4764. }
  4765.  
  4766. void Actualize_Sample_Ed(int typex, char gode)
  4767. {
  4768. CheckLoops();
  4769.  
  4770. if(userscreen==2){
  4771.  
  4772. switch(seditor)
  4773. {
  4774. case 0:
  4775.  
  4776. if (gode==0 || gode==1){
  4777. if (SampleVol[ped_patsam][ped_split]>4.0f)SampleVol[ped_patsam][ped_split]=4.0f;
  4778. if (SampleVol[ped_patsam][ped_split]<0)SampleVol[ped_patsam][ped_split]=0;
  4779. Realslider(426,408,f2i(SampleVol[ped_patsam][ped_split]*32.0f));
  4780. outlong(575,409,f2i(SampleVol[ped_patsam][ped_split]*100.0f),1);
  4781. }
  4782.  
  4783. if (gode==0 || gode==2){
  4784. if (Finetune[ped_patsam][ped_split]>127)Finetune[ped_patsam][ped_split]=127;
  4785. if (Finetune[ped_patsam][ped_split]<-127)Finetune[ped_patsam][ped_split]=-127;
  4786. Realslider(426,426,64+(Finetune[ped_patsam][ped_split]/2));
  4787. outlong(575,427,(long)Finetune[ped_patsam][ped_split],0);
  4788. }
  4789.  
  4790. if (gode==0 || gode==3){
  4791. if (FDecay[ped_patsam][ped_split]>0.015625f)FDecay[ped_patsam][ped_split]=0.015625f;
  4792. if (FDecay[ped_patsam][ped_split]<0.0f)FDecay[ped_patsam][ped_split]=0.0f;
  4793. Realslider(52,408,f2i(FDecay[ped_patsam][ped_split]*8192.0f));
  4794. outlong(201,408,f2i(FDecay[ped_patsam][ped_split]*8192.0f),0);
  4795. }
  4796.  
  4797. if (gode==0)
  4798. {
  4799. if (typex==1 || typex==2)
  4800. {
  4801. if (SampleType[ped_patsam][ped_split]!=0)
  4802. {
  4803. char temprout[256];
  4804. if (SampleChannels[ped_patsam][ped_split]==2)
  4805. sprintf(temprout,"%s [Stereo]",SampleName[ped_patsam][ped_split]);
  4806. else
  4807. sprintf(temprout,"%s [Mono]",SampleName[ped_patsam][ped_split]);
  4808. guiDial3(7,347,256,16,temprout,200);
  4809. }
  4810. else
  4811. {
  4812. guiDial3(7,347,256,16,"No Sample Loaded",200);
  4813. }
  4814. }
  4815. }// typex
  4816.  
  4817. if (gode==0 || gode==4)
  4818. outlong(448,337,SampleNumSamples[ped_patsam][ped_split],0);
  4819.  
  4820. if (gode==0 || gode==5){
  4821. outlong(448,355,LoopStart[ped_patsam][ped_split],0);
  4822. outlong(448,373,LoopEnd[ped_patsam][ped_split],0);
  4823.  
  4824. if (LoopType[ped_patsam][ped_split])
  4825. {
  4826.     guiDial(448,391,29,16,"On",100);
  4827.     guiDial(479,391,29,16,"Off",200);
  4828. }
  4829. else
  4830. {
  4831.     guiDial(448,391,29,16,"On",200);
  4832.     guiDial(479,391,29,16,"Off",100);
  4833. }
  4834. }
  4835.  
  4836. if (gode==0 || gode==8)
  4837. {valuer_box(570,337,ped_split);
  4838. valuer_box3(570,355,Basenote[ped_patsam][ped_split]);}
  4839.  
  4840. if (gode==0 || gode==9)
  4841. valuer_box3(570,355,Basenote[ped_patsam][ped_split]);
  4842.  
  4843. if (gode==0 || gode==10)
  4844. valuer_box(570,373,Midiprg[ped_patsam]+1);
  4845.  
  4846. if (gode==0 || gode==11){
  4847. if(Synthprg[ped_patsam]){
  4848.     guiDial(570,391,28,16,"Off",200);
  4849.     guiDial(602,391,28,16,"On",100);
  4850. }else{
  4851.     guiDial(570,391,28,16,"Off",100);
  4852.     guiDial(602,391,28,16,"On",200);}
  4853. }
  4854.  
  4855.  
  4856. if (gode==0 || gode==12){
  4857. if(beatsync[ped_patsam]){
  4858.     guiDial(144,372,28,16,"Off",200);
  4859.     guiDial(174,372,28,16,"On",100);
  4860. }else{
  4861.     guiDial(144,372,28,16,"Off",100);
  4862.     guiDial(174,372,28,16,"On",200);}
  4863.  
  4864. }
  4865.  
  4866. if (gode==0 || gode==13)valuer_box2(144,390,beatlines[ped_patsam]);
  4867.  
  4868. if (gode==14)
  4869. {
  4870. guiDial(268,364,88,16,"Export .Wav File",100);
  4871. char buffer[64];
  4872.  
  4873. mess_box("Writting Wav Header And Sample Data...");
  4874.  
  4875. WaveFile RF;
  4876.  
  4877. RF.OpenForWrite(SampleName[ped_patsam][ped_split],44100,16,SampleChannels[ped_patsam][ped_split]);
  4878.  
  4879. bool t_stereo;
  4880.  
  4881. if(SampleChannels[ped_patsam][ped_split]==1)
  4882. t_stereo=false;
  4883. else 
  4884. t_stereo=true;
  4885.  
  4886. long woff=0;
  4887.  
  4888. short *eSamples=RawSamples[ped_patsam][0][ped_split];
  4889. short *erSamples=RawSamples[ped_patsam][1][ped_split];
  4890.  
  4891. while(woff<SampleNumSamples[ped_patsam][ped_split]){
  4892. if (t_stereo)
  4893. RF.WriteStereoSample(*eSamples++,*erSamples++);
  4894. else
  4895. RF.WriteMonoSample(*eSamples++);
  4896.  
  4897. woff++;
  4898. }
  4899.  
  4900. RF.Close();
  4901. sprintf(buffer,"File '%s' saved...",SampleName[ped_patsam][ped_split]);
  4902. mess_box(buffer);
  4903.  
  4904. guiDial(268,364,88,16,"Export .Wav File",200);
  4905. }
  4906.  
  4907. if (gode==0 || gode==15){
  4908. if (CustomVol[ped_patsam]>1.0f)CustomVol[ped_patsam]=1.0f;
  4909. if (CustomVol[ped_patsam]<0.0f)CustomVol[ped_patsam]=0.0f;
  4910. Realslider(52,426,f2i(CustomVol[ped_patsam]*128.0f));
  4911. outlong(201,426,f2i(CustomVol[ped_patsam]*100.0f),1);
  4912. }
  4913.  
  4914. break;
  4915.  
  4916. case 1:
  4917. if(typex==0)
  4918. {
  4919. outlong(484,355,*(RawSamples[ped_patsam][0][ped_split]+LoopStart[ped_patsam][ped_split]),0);
  4920. outlong(114,350,LoopStart[ped_patsam][ped_split],0);
  4921. actuloop=1;
  4922. }
  4923.  
  4924. if(typex==1)
  4925. {
  4926. outlong(484,373,*(RawSamples[ped_patsam][0][ped_split]+LoopEnd[ped_patsam][ped_split]),0);
  4927. outlong(314,350,LoopEnd[ped_patsam][ped_split],0);
  4928. actuloop=2;
  4929. }
  4930.  
  4931. if(typex==2)
  4932. {
  4933. outlong(484,355,*(RawSamples[ped_patsam][0][ped_split]+LoopStart[ped_patsam][ped_split]),0);
  4934. outlong(484,373,*(RawSamples[ped_patsam][0][ped_split]+LoopEnd[ped_patsam][ped_split]),0);
  4935. outlong(114,350,LoopStart[ped_patsam][ped_split],0);
  4936. outlong(314,350,LoopEnd[ped_patsam][ped_split],0);
  4937. actuloop=3;
  4938. }
  4939.  
  4940. break;
  4941. }//SWitch draw sampleeditor
  4942.  
  4943. }//User screen==2
  4944. }
  4945.  
  4946. void outlong(int x,int y, long cant,int mode)
  4947. {
  4948. char xstr[40];
  4949. switch (mode){
  4950. case 0:sprintf(xstr,"%d",cant);break;
  4951. case 1:sprintf(xstr,"%d%%",cant);break;
  4952. case 2:sprintf(xstr,"%d ms.",cant);break;
  4953. case 3:sprintf(xstr,"%d Hz.",cant);break;
  4954. case 5:sprintf(xstr,"%d K.",cant);break;
  4955. case 6:sprintf(xstr,"%d Degr.",cant);break;
  4956. case 10:sprintf(xstr,"S: %d",cant);break;
  4957. case 11:sprintf(xstr,"E: %d",cant);break;
  4958. case 12:sprintf(xstr,"L: %d",cant);break;
  4959. }
  4960. guiDial3(x,y,60,16,xstr,150);
  4961. }
  4962.  
  4963. void outfloat(int x,int y, float cant,int mode)
  4964. {
  4965. char xstr[40];
  4966.  
  4967. switch (mode){
  4968. case 0:sprintf(xstr,"%.3f",cant);break;
  4969. case 1:sprintf(xstr,"%.2f%%",cant);break;
  4970. case 2:sprintf(xstr,"%.3f ms.",cant);break;
  4971. case 3:sprintf(xstr,"%.3f Hz.",cant);break;
  4972. case 5:sprintf(xstr,"%.3f K.",cant);break;
  4973. case 8:sprintf(xstr,"%.1f Tk.",cant);break;
  4974. }
  4975.  
  4976. guiDial3(x,y,60,16,xstr,150);
  4977. }
  4978.  
  4979.  
  4980. void DoEffects(void)
  4981. {
  4982.  
  4983. for (int trackef=0;trackef<Songtracks;trackef++)
  4984. {
  4985.     int tefactor=trackef*6+ped_line*96+pSequence[cPosition]*12288;
  4986.     int pltr_note=*(RawPatterns+tefactor);
  4987.     int pltr_sample=*(RawPatterns+tefactor+1);
  4988.     unsigned char pltr_vol_row=*(RawPatterns+tefactor+2);
  4989.     int pltr_pan_row=*(RawPatterns+tefactor+3);
  4990.     __int64 pltr_eff_row=*(RawPatterns+tefactor+4);
  4991.     __int64 pltr_dat_row=*(RawPatterns+tefactor+5);
  4992.     
  4993.     if (Subicounter==0)
  4994.     {
  4995.         if (pltr_note==121 && pltr_sample!=255)sp_Tvol[trackef]=CustomVol[pltr_sample];
  4996.            
  4997.     }
  4998.  
  4999.     // AUTOFADE ROUTINE
  5000.  
  5001.     switch(FADEMODE[trackef])
  5002.         {
  5003.         case 1:
  5004.             sp_Tvol[trackef]+=FADECOEF[trackef];
  5005.             
  5006.             if(sp_Tvol[trackef]>1.0f)
  5007.             {    sp_Tvol[trackef]=1.0f;
  5008.             FADEMODE[trackef]=0;}
  5009.         break;
  5010.  
  5011.         case 2:
  5012.             sp_Tvol[trackef]-=FADECOEF[trackef];
  5013.             
  5014.             if(sp_Tvol[trackef]<0.0f)
  5015.             {    sp_Tvol[trackef]=0.0f;
  5016.             FADEMODE[trackef]=0;}
  5017.         break;
  5018.     }
  5019.  
  5020.     // EFFECTS
  5021.  
  5022.     if ((pltr_vol_row&0xf0)==0xf0) /* Note Cut: Fx */
  5023.     {
  5024.         unsigned char kinder=pltr_vol_row&0xf;
  5025.         if (Subicounter==kinder )
  5026.         {
  5027.         if(sp_Stage[trackef]!=0)
  5028.         {
  5029.             if(FType[trackef]==4)
  5030.             sp_Stage[trackef]=2;
  5031.             else
  5032.             sp_Tvol[trackef]=0.001f;
  5033.         }
  5034.  
  5035.         Synthesizer[trackef].SynthNoteOff();
  5036.         if (c_midiout!=-1)midiOutShortMsg(midiout_handle, (176+TRACKMIDICHANNEL[trackef]) | (123 << 8) | (0 << 16)); 
  5037.         }
  5038.     }
  5039.     
  5040.     if (sp_Stage[trackef]!=0)
  5041.     {
  5042.     
  5043.         switch(pltr_eff_row)
  5044.         {
  5045.             // d01 $01 Pitch Up 
  5046.             case 1:
  5047.             if(Vstep1[trackef]<137438953472)Vstep1[trackef]+=pltr_dat_row<<21;
  5048.             break;
  5049.             
  5050.             // d02 $02 Pitch Down 
  5051.             case 2:
  5052.             Vstep1[trackef]-=pltr_dat_row<<21;
  5053.             if(Vstep1[trackef]<16)Vstep1[trackef]=16;
  5054.             break;
  5055.             
  5056.             case 3:
  5057.             sp_Tvol[trackef]=pltr_dat_row*0.0039062f;
  5058.             break;
  5059.             
  5060.             case 4: // Slicer
  5061.             if (Subicounter==0)
  5062.             sp_Tvol[trackef]=1.0f;
  5063.             
  5064.             if (Subicounter>=pltr_dat_row)
  5065.             sp_Tvol[trackef]=0;
  5066.             break;
  5067.  
  5068.             case 5: // Glider
  5069.             if(pltr_dat_row)glidestep[trackef]=pltr_dat_row<<22;
  5070.  
  5071.             if (Vstep1[trackef]<sp_Step[trackef])
  5072.             {
  5073.             Vstep1[trackef]+=glidestep[trackef];
  5074.             if (Vstep1[trackef]>sp_Step[trackef])Vstep1[trackef]=sp_Step[trackef];
  5075.             }
  5076.             else if (Vstep1[trackef]>sp_Step[trackef])
  5077.             {
  5078.             Vstep1[trackef]-=glidestep[trackef];
  5079.             if (Vstep1[trackef]<sp_Step[trackef])Vstep1[trackef]=sp_Step[trackef];
  5080.             }
  5081.             break;
  5082.  
  5083.         }// SWITCH CASES
  5084.     }//IF PLAYING TRACK...
  5085.  
  5086.         switch(pltr_eff_row)
  5087.         {
  5088.             // d08 $08 SetCutOff 
  5089.             case 8:
  5090.             TCut[trackef]=(float)pltr_dat_row/2.0f;
  5091.             break;
  5092.  
  5093.             // d10 $0a SetRandomCutOff 
  5094.             case 10:
  5095.                 if (Subicounter==0){
  5096.             TCut[trackef]=float((float)(rand()/256)/((float)pltr_dat_row+1.0));
  5097.             
  5098.             if (TCut[trackef]<1)
  5099.             TCut[trackef]=1;
  5100.  
  5101.             if (TCut[trackef]>127)
  5102.                 TCut[trackef]=127;}
  5103.  
  5104.             break;
  5105.  
  5106.             // d11 $0b SlideUpCutOff 
  5107.             case 11:
  5108.             if (Subicounter==0){TCut[trackef]+=pltr_dat_row;if (TCut[trackef]>127)TCut[trackef]=127;}
  5109.             break;
  5110.  
  5111.             // d12 $0c SlideDownCutOff 
  5112.             case 12:
  5113.             if (Subicounter==0){TCut[trackef]-=pltr_dat_row;if (TCut[trackef]<1)TCut[trackef]=1;}
  5114.             break;
  5115.  
  5116.             // d14 $0e Retrigger Command
  5117.             case 14: 
  5118.                 
  5119.                 if (pltr_dat_row>0 && (Subicounter % pltr_dat_row)==0){            
  5120.                     if (pltr_vol_row<=64)
  5121.                     Sp_Playwave(trackef, (float)pltr_note, pltr_sample,pltr_vol_row*0.015625f,0,0);
  5122.                     else
  5123.                     Sp_Playwave(trackef, (float)pltr_note, pltr_sample,CustomVol[pltr_sample],0,0);
  5124.                 }
  5125.             break;
  5126.  
  5127.             
  5128.             // SET BPM
  5129.             case 240:
  5130.             if(pltr_dat_row>32)
  5131.             {
  5132.             BeatsPerMin=pltr_dat_row;
  5133.             SamplesPerTick=(int)((60 * SamplesPerSec) / (BeatsPerMin * TicksPerBeat));  
  5134.             SamplesPerSub=SamplesPerTick/6;
  5135.             }
  5136.             break;
  5137.  
  5138.             /* &15 Speed */
  5139.             case 15:
  5140.             TicksPerBeat=pltr_dat_row;
  5141.             if (TicksPerBeat<1)TicksPerBeat=1;
  5142.             if (TicksPerBeat>16)TicksPerBeat=16;
  5143.             SamplesPerTick=(int)((60 * SamplesPerSec) / (BeatsPerMin * TicksPerBeat));  
  5144.             SamplesPerSub=SamplesPerTick/6;
  5145.             if (shuffleswitch==1)
  5146.             shufflestep=-((SamplesPerTick*shuffle)/200);
  5147.             else
  5148.             shufflestep=(SamplesPerTick*shuffle)/200;
  5149.             break;
  5150.         
  5151.             // d16 $10 Send to delay Command
  5152.             case 16: 
  5153.                 CCoef[trackef]=(float)pltr_dat_row/255.0f;
  5154.             break;
  5155.  
  5156.             // d17 $11 Send to reverb Command
  5157.             case 17: 
  5158.             DSend[trackef]=(float)pltr_dat_row/255.0f;
  5159.             break;
  5160.  
  5161.             // d18 $12 Set Threshold
  5162.             case 18: 
  5163.             DThreshold[trackef]=(float)pltr_dat_row*128.0f;
  5164.             break;
  5165.             
  5166.             // d19  $13 Clamp
  5167.             case 19: 
  5168.             DClamp[trackef]=(float)pltr_dat_row*128.0f;
  5169.             break;
  5170.             
  5171.             // d20  $14 Filter Reso
  5172.             case 20: 
  5173.             FRez[trackef]=pltr_dat_row/2;
  5174.             break;
  5175.             
  5176.             // d21 $15 Filter Type
  5177.             case 21: 
  5178.             if (pltr_dat_row<=MAX_FILTER)FType[trackef]=pltr_dat_row;
  5179.             break;
  5180.         
  5181.              /* &16 Reset lfo */
  5182.             case 22:
  5183.             LFOGR[trackef]=0.0f;
  5184.             break;
  5185.         
  5186.             case 23: 
  5187.             if(pltr_dat_row>0)
  5188.             {
  5189.             FADECOEF[trackef]=0.1666667f/(float)pltr_dat_row;
  5190.             FADEMODE[trackef]=1;
  5191.             }
  5192.             break;
  5193.         
  5194.             case 24: 
  5195.             if(pltr_dat_row>0)
  5196.             {
  5197.             FADECOEF[trackef]=0.1666667f/(float)pltr_dat_row;
  5198.             FADEMODE[trackef]=2;
  5199.             }
  5200.             break;
  5201.  
  5202.             case 25: 
  5203.             sp_Tvol[trackef]+=pltr_dat_row*0.0039062f;
  5204.             if(sp_Tvol[trackef]>1.0f)sp_Tvol[trackef]=1.0f;
  5205.             break;
  5206.         
  5207.             case 26: 
  5208.             sp_Tvol[trackef]-=pltr_dat_row*0.0039062f;
  5209.             if(sp_Tvol[trackef]<0.0f)sp_Tvol[trackef]=0.0f;
  5210.             break;
  5211.         
  5212.         }
  5213. }//FOR BUCLE ON TRACKS
  5214.  
  5215. }// Function of pattern effects
  5216.  
  5217.  
  5218. void Actualize_Main_Ed(void)
  5219. {
  5220. if (userscreen==0)
  5221. {
  5222.     char tname[32];
  5223.  
  5224.     if (snamesel==1)
  5225.     {
  5226.         sprintf(tname,"%s_",name);
  5227.         guiDial(90,386,162,16,tname,100);
  5228.     }
  5229.     else
  5230.     {
  5231.         sprintf(tname,"%s",name);
  5232.         guiDial(90,386,162,16,tname,140);
  5233.     }
  5234.  
  5235.     if (snamesel==4)
  5236.     {
  5237.         sprintf(tname,"%s_",artist);
  5238.         guiDial(90,404,162,16,tname,100);
  5239.     }
  5240.     else
  5241.     {
  5242.         sprintf(tname,"%s",artist);
  5243.         guiDial(90,404,162,16,tname,140);
  5244.     }
  5245.     
  5246.     if (snamesel==5)
  5247.     {
  5248.         sprintf(tname,"%s_",style);
  5249.         guiDial(90,422,162,16,tname,100);
  5250.     }
  5251.     else
  5252.     {
  5253.         sprintf(tname,"%s",style);
  5254.         guiDial(90,422,162,16,tname,140);
  5255.     }
  5256.  
  5257.     valuer_box(482,350,XLATENCY_TIME);
  5258.     outlong(544,350,XLATENCY_TIME,2);
  5259.  
  5260. GlobalMemoryStatus(&memstate);
  5261. char mdis[80];
  5262. sprintf(mdis,"Memory Status. (Memory load: %d%%)",memstate.dwMemoryLoad,200);
  5263. guiDial3(344,386,246,16,mdis,150);
  5264. guiDial3(344,404,60,18,"Total Phys.",200);
  5265. outlong(344,424,memstate.dwTotalPhys/1024,5); 
  5266. guiDial3(406,404,60,18,"Avail Phys.",200);
  5267. outlong(406,424,memstate.dwAvailPhys/1024,5);
  5268. guiDial3(468,404,60,18,"Total Vrtl.",200);
  5269. outlong(468,424,memstate.dwTotalVirtual/1024,5); 
  5270. guiDial3(530,404,60,18,"Avail Vrtl.",200);
  5271. outlong(530,424,memstate.dwAvailVirtual/1024,5);
  5272.  
  5273. if(QUALITYCHANGE){
  5274. if(QUALITYPLAY==0)mess_box("NTK Level 2 Audio Engine [All Features Enabled, Highest CPU usage]. CSynth Enabled, all DSP units enabled.");
  5275. if(QUALITYPLAY==1)mess_box("NTK Level 1 Audio Engine [CSynth: Disabled, Flanger Engine: Off, Medium CPU usage]");
  5276. if(QUALITYPLAY==2)mess_box("NTK Level 0 Audio Engine [Standard 16 Channel Mod, No Effects, No CSynth, No Filters, Lowest CPU usage]");
  5277. QUALITYCHANGE=false;
  5278. }
  5279.  
  5280. switch(QUALITYPLAY)
  5281. {
  5282. case 0:
  5283. guiDial(264,368,64,16,"Highest",100);
  5284. guiDial(264,386,64,16,"Medium",200);
  5285. guiDial(264,404,64,16,"Lowest",200);
  5286. break;
  5287. case 1:
  5288. guiDial(264,368,64,16,"Highest",200);
  5289. guiDial(264,386,64,16,"Medium",100);
  5290. guiDial(264,404,64,16,"Lowest",200);
  5291. break;
  5292. case 2:
  5293. guiDial(264,368,64,16,"Highest",200);
  5294. guiDial(264,386,64,16,"Medium",200);
  5295. guiDial(264,404,64,16,"Lowest",100);
  5296. break;
  5297. }
  5298.  
  5299. }
  5300.  
  5301. }
  5302.  
  5303. void draw_mained(void)
  5304. {
  5305. guiDial(112,309,64,16,"Track FX",200);
  5306. guiDial(178,309,64,16,"Midi/CSynth",200);
  5307. guiDial(244,309,64,16,"Master",200);
  5308. guiDial(310,309,64,16,"Sequencer",200);
  5309. guiDial(376,309,64,16,"Disk IO",100);
  5310. guiDial(442,309,64,16,"Track",200);
  5311. guiDial(508,309,64,16,"Instrument",200);
  5312. guiDial(574,309,64,16,"FX Setup",200);
  5313. guiDial(640,309,64,16,"Extend Edit",200);
  5314. guiDial(706,309,64,16,"303",200);
  5315.  
  5316. guiDial2("Disk Operations / Playback Latency / Song Credits");
  5317. guiDial(8,350,80,16,"Load Song",200);
  5318. guiDial(8,368,80,16,"Save Song",200);
  5319. guiDial3(8,386,80,16,"Title",190);
  5320. guiDial3(8,404,80,16,"Produced By",190);
  5321. guiDial3(8,422,80,16,"Style",190);
  5322. guiDial(90,350,80,16,"New Song",200);
  5323. guiDial(90,368,80,16,"WAV Render",200);
  5324. guiDial(172,350,80,16,"Save Inst",200);
  5325. guiDial(172,368,80,16,"Show Info",200);
  5326. guiDial3(344,350,136,16,"SoundCard Latency",200);
  5327.  
  5328. guiDial3(264,350,64,16,"CPU Usage",200);
  5329.  
  5330. S->printXY(344,368,0x00888888,"The lower latency the higher CPU and clicking probability.");
  5331. }
  5332.  
  5333. void SaveMod(void)
  5334. {
  5335. FILE *in;
  5336. char Temph[96];
  5337. char extension[10];
  5338. sprintf(extension,"TWNNSNG2");
  5339.  
  5340. sprintf (Temph,"Saving '%s.ntk' song on current directory...",name);
  5341. mess_box(Temph);    
  5342. sprintf(Temph,"%s.ntk",name);
  5343. in = fopen(Temph,"wb");
  5344. if (in!=NULL)
  5345. {
  5346. // Writing NoiseTrekker header & name...
  5347. fwrite(extension, sizeof( char),9,in);
  5348. fwrite(name, sizeof( char ), 20,in);
  5349. fwrite(&nPatterns, sizeof(unsigned char ), 1,in);
  5350. fwrite(&sLength, sizeof(unsigned char ), 1,in);
  5351. fwrite(pSequence, sizeof(unsigned char ), 256,in);
  5352. fwrite(patternLines, sizeof(short ),128,in);
  5353.  
  5354. for (int pwrite=0;pwrite<nPatterns;pwrite++)
  5355. fwrite(RawPatterns+pwrite*12288, 12288,1,in);
  5356.  
  5357. // Writing sample data
  5358. for (int swrite=0;swrite<128;swrite++)
  5359. {
  5360. fwrite(&nameins[swrite], sizeof( char ), 20,in);
  5361. fwrite(&Midiprg[swrite],sizeof(char),1,in);
  5362. fwrite(&Synthprg[swrite],sizeof(bool),1,in);
  5363. fwrite(&PARASynth[swrite], sizeof(SynthParameters),1,in);
  5364.  
  5365. for (int slwrite=0;slwrite<16;slwrite++)
  5366. {
  5367. fwrite(&SampleType[swrite][slwrite], sizeof(char ),1,in);
  5368. if (SampleType[swrite][slwrite]!=0)
  5369. {
  5370. fwrite(&SampleName[swrite][slwrite], sizeof(char),256,in);
  5371. fwrite(&Basenote[swrite][slwrite],sizeof(char),1,in);
  5372. fwrite(&LoopStart[swrite][slwrite], sizeof(long ),1,in);
  5373. fwrite(&LoopEnd[swrite][slwrite], sizeof(long ),1,in);
  5374. fwrite(&LoopType[swrite][slwrite], sizeof(char ),1,in);
  5375. fwrite(&SampleNumSamples[swrite][slwrite], sizeof(long ),1,in);
  5376. fwrite(&Finetune[swrite][slwrite], sizeof(char ),1,in);
  5377. fwrite(&SampleVol[swrite][slwrite], sizeof(float ),1,in);
  5378. fwrite(&FDecay[swrite][slwrite], sizeof(float ),1,in);
  5379.  
  5380. fwrite(RawSamples[swrite][0][slwrite], sizeof(short),SampleNumSamples[swrite][slwrite],in);
  5381. fwrite(&SampleChannels[swrite][slwrite], sizeof(char ),1,in);
  5382. if (SampleChannels[swrite][slwrite]==2)
  5383. fwrite(RawSamples[swrite][1][slwrite], sizeof(short),SampleNumSamples[swrite][slwrite],in);
  5384. }// Exist Sample
  5385. }
  5386. }
  5387.  
  5388. // Writing Track Propertiers
  5389. for (int twrite=0;twrite<MAX_TRACKS;twrite++)
  5390. {
  5391. fwrite(&TCut[twrite], sizeof(float ),1,in);
  5392. fwrite(&ICut[twrite], sizeof(float ),1,in);
  5393. fwrite(&TPan[twrite], sizeof(float ),1,in);
  5394. fwrite(&FType[twrite], sizeof(int ),1,in);
  5395. fwrite(&FRez[twrite], sizeof(int ),1,in);
  5396. fwrite(&DThreshold[twrite], sizeof(float ),1,in);
  5397. fwrite(&DClamp[twrite], sizeof(float ),1,in);
  5398. fwrite(&DSend[twrite], sizeof(float ),1,in);
  5399. fwrite(&CSend[twrite], sizeof(int ),1,in);
  5400. }
  5401.  
  5402. // Writing mod properties
  5403. fwrite(&compressor, sizeof(int),1,in);
  5404. fwrite(&c_threshold, sizeof(int),1,in);
  5405. fwrite(&BeatsPerMin, sizeof(int ),1,in);
  5406. fwrite(&TicksPerBeat, sizeof(int ),1,in);
  5407. fwrite(&mas_vol, sizeof(float),1,in);
  5408. fwrite(&delay_time, sizeof(int ),1,in);
  5409. fwrite(&Feedback, sizeof(float ),1,in);
  5410. fwrite(&DelayType, sizeof(int ),1,in);
  5411. fwrite(&lchorus_delay, sizeof(int ),1,in);
  5412. fwrite(&rchorus_delay, sizeof(int ),1,in);
  5413. fwrite(&lchorus_feedback, sizeof(float ),1,in);
  5414. fwrite(&rchorus_feedback, sizeof(float ),1,in);
  5415. fwrite(&shuffle, sizeof(int),1,in);
  5416.  
  5417. // Writing part sequence data
  5418.  
  5419. for (int tps_pos=0;tps_pos<256;tps_pos++)
  5420. for (int tps_trk=0;tps_trk<16;tps_trk++)
  5421. fwrite(&SACTIVE[tps_pos][tps_trk],sizeof(bool),1,in);
  5422.  
  5423. for (twrite=0;twrite<MAX_TRACKS;twrite++)
  5424. fwrite(&TRACKMIDICHANNEL[twrite], sizeof(int),1,in);
  5425.  
  5426. for (twrite=0;twrite<MAX_TRACKS;twrite++)
  5427. {
  5428. fwrite(&LFO_ON[twrite], sizeof(char),1,in);
  5429. fwrite(&LFORATE[twrite], sizeof(float),1,in);
  5430. fwrite(&LFOAMPL[twrite], sizeof(float),1,in);
  5431. }
  5432.  
  5433. for (twrite=0;twrite<MAX_TRACKS;twrite++){
  5434. fwrite(&FLANGER_ON[twrite], sizeof(char),1,in);
  5435. fwrite(&FLANGER_AMOUNT[twrite], sizeof(float),1,in);
  5436. fwrite(&FLANGER_DEPHASE[twrite], sizeof(float),1,in);
  5437. fwrite(&FLANGER_RATE[twrite], sizeof(float),1,in);
  5438. fwrite(&FLANGER_AMPL[twrite], sizeof(float),1,in);
  5439. fwrite(&FLANGER_FEEDBACK[twrite], sizeof(float),1,in);
  5440. fwrite(&FLANGER_DELAY[twrite], sizeof(int),1,in);
  5441. }
  5442. fwrite(&FLANGER_DEPHASE, sizeof(float),1,in);
  5443.  
  5444. for (char tps_trk=0;tps_trk<16;tps_trk++)
  5445. fwrite(&TRACKSTATE[tps_trk],sizeof(int),1,in);
  5446.  
  5447. fwrite(&Songtracks,sizeof(char),1,in);
  5448.  
  5449. for (tps_trk=0;tps_trk<16;tps_trk++)
  5450. {
  5451. fwrite(&Disclap[tps_trk],sizeof(bool),1,in);
  5452. fwrite(&Dispan[tps_trk],sizeof(bool),1,in);
  5453. }
  5454.  
  5455. fwrite(artist, sizeof( char ), 20,in);
  5456. fwrite(style, sizeof( char ), 20,in);
  5457. fwrite(&QUALITYPLAY, sizeof( char ), 1,in);
  5458.  
  5459. fwrite(beatsync,sizeof(bool),128,in);
  5460. fwrite(beatlines,sizeof(short),128,in);
  5461. fwrite(&REVERBFILTER,sizeof(float),1,in);
  5462. fwrite(CustomVol,sizeof(float),128,in);
  5463. fwrite(&AMIMODE,sizeof(bool),1,in);
  5464. fwrite(&tb303,sizeof(para303),2,in);
  5465. fwrite(&tb303engine[0].tbVolume,sizeof(float),1,in);
  5466. fwrite(&tb303engine[1].tbVolume,sizeof(float),1,in);
  5467. fwrite(&tb303engine[0].hpf,sizeof(bool),1,in);
  5468. fwrite(&tb303engine[1].hpf,sizeof(bool),1,in);
  5469.  
  5470. fclose(in);
  5471. last_index=-1;
  5472. Read_SMPT();
  5473. ltActualize(0);
  5474.  
  5475. mess_box("Module saved succesful...");
  5476. }
  5477. else
  5478. {
  5479. mess_box("Module save failed...");    
  5480. }
  5481. if (snamesel==1 || snamesel==4 || snamesel==5){snamesel=0;Actualize_Main_Ed();}
  5482. }
  5483.  
  5484. void LoadMod(void)
  5485. {
  5486. SongStop();
  5487. mess_box("Attempting to load the song file...");
  5488.  
  5489. Sleep(1000);    
  5490. FILE *in;
  5491. in = fopen(name,"rb");
  5492.  
  5493. if (in!=NULL)
  5494. {
  5495. // Reading and checking extension...
  5496. char extension[10];
  5497. fread(extension, sizeof( char),9,in);
  5498. if (strcmp(extension,"TWNNSNG2")==0)
  5499. { /* Ok, extension match! */
  5500. mess_box("Loading 'NoiseTrekker' song -> Header");    
  5501.  
  5502. FreeAll();
  5503.  
  5504. for (int inicial=0;inicial<PBLEN;inicial+=6)
  5505. {
  5506.     *(RawPatterns+inicial)=121;//121
  5507.     *(RawPatterns+inicial+1)=255;//255
  5508.     *(RawPatterns+inicial+2)=255;//255
  5509.     *(RawPatterns+inicial+3)=255;//255
  5510.     *(RawPatterns+inicial+4)=0;//0
  5511.     *(RawPatterns+inicial+5)=0;//0
  5512. }
  5513.  
  5514. init_sample_bank();
  5515. Iniplayer();
  5516.  
  5517. fread(name, sizeof( char ), 20,in);
  5518. fread(&nPatterns, sizeof(unsigned char ), 1,in);
  5519. fread(&sLength, sizeof(unsigned char ), 1,in);
  5520. fread(pSequence, sizeof(unsigned char ), 256,in);
  5521. fread(patternLines, sizeof(short),128,in);
  5522.  
  5523. for (int pwrite=0;pwrite<nPatterns;pwrite++)
  5524. fread(RawPatterns+pwrite*12288, 12288,1,in);
  5525.  
  5526. mess_box("Loading 'NoiseTrekker' song -> Sample data");    
  5527.  
  5528. for (int swrite=0;swrite<128;swrite++)
  5529. {
  5530. fread(&nameins[swrite], sizeof( char ), 20,in);
  5531. fread(&Midiprg[swrite],sizeof(char),1,in);
  5532. fread(&Synthprg[swrite],sizeof(bool),1,in);
  5533. fread(&PARASynth[swrite], sizeof(SynthParameters),1,in);
  5534.  
  5535. for (int slwrite=0;slwrite<16;slwrite++)
  5536. {
  5537. fread(&SampleType[swrite][slwrite], sizeof(char ),1,in);
  5538. if (SampleType[swrite][slwrite]!=0)
  5539. {
  5540. fread(&SampleName[swrite][slwrite], sizeof(char),256,in);
  5541. fread(&Basenote[swrite][slwrite],sizeof(char),1,in);
  5542. fread(&LoopStart[swrite][slwrite], sizeof(long ),1,in);
  5543. fread(&LoopEnd[swrite][slwrite], sizeof(long ),1,in);
  5544. fread(&LoopType[swrite][slwrite], sizeof(char ),1,in);
  5545. fread(&SampleNumSamples[swrite][slwrite], sizeof(long ),1,in);
  5546. fread(&Finetune[swrite][slwrite], sizeof(char ),1,in);
  5547. fread(&SampleVol[swrite][slwrite], sizeof(float ),1,in);
  5548. fread(&FDecay[swrite][slwrite], sizeof(float ),1,in);
  5549. RawSamples[swrite][0][slwrite]=(short *)malloc(SampleNumSamples[swrite][slwrite]*2);
  5550. fread(RawSamples[swrite][0][slwrite], sizeof(short),SampleNumSamples[swrite][slwrite],in);
  5551. fread(&SampleChannels[swrite][slwrite], sizeof(char ),1,in);
  5552. if (SampleChannels[swrite][slwrite]==2)
  5553. {
  5554. RawSamples[swrite][1][slwrite]=(short *)malloc(SampleNumSamples[swrite][slwrite]*2);
  5555. fread(RawSamples[swrite][1][slwrite], sizeof(short),SampleNumSamples[swrite][slwrite],in);
  5556. }
  5557. }// Exist Sample
  5558. }
  5559. }
  5560.  
  5561. mess_box("Loading 'NoiseTrekker' song -> Track info, patterns and sequence.");    
  5562.  
  5563. // Reading Track Propertiers
  5564. for (int twrite=0;twrite<MAX_TRACKS;twrite++)
  5565. {
  5566. fread(&TCut[twrite], sizeof(float ),1,in);
  5567. fread(&ICut[twrite], sizeof(float ),1,in);
  5568. if (ICut[ped_track]>0.0078125f)ICut[ped_track]=0.0078125f;
  5569. if (ICut[ped_track]<0.00006103515625f)ICut[ped_track]=0.00006103515625f;
  5570.  
  5571. fread(&TPan[twrite], sizeof(float ),1,in);
  5572. ComputeStereo(twrite);
  5573. fread(&FType[twrite], sizeof(int ),1,in);
  5574. fread(&FRez[twrite], sizeof(int ),1,in);
  5575. fread(&DThreshold[twrite], sizeof(float ),1,in);
  5576. fread(&DClamp[twrite], sizeof(float ),1,in);
  5577. fread(&DSend[twrite], sizeof(float ),1,in);
  5578. fread(&CSend[twrite], sizeof(int ),1,in);
  5579. }
  5580.  
  5581. // Reading mod properties
  5582. fread(&compressor, sizeof(int ),1,in);
  5583. fread(&c_threshold, sizeof(int ),1,in);
  5584. fread(&BeatsPerMin, sizeof(int ),1,in);
  5585. fread(&TicksPerBeat, sizeof(int ),1,in);
  5586. fread(&mas_vol, sizeof(float ),1,in);
  5587. if (mas_vol<0.01f)mas_vol=0.01f;
  5588. if (mas_vol>1.0f)mas_vol=1.0f;
  5589. fread(&delay_time, sizeof(int ),1,in);
  5590. fread(&Feedback, sizeof(float ),1,in);
  5591. fread(&DelayType, sizeof(int ),1,in);
  5592. fread(&lchorus_delay, sizeof(int),1,in);
  5593. fread(&rchorus_delay, sizeof(int),1,in);
  5594. fread(&lchorus_feedback, sizeof(float),1,in);
  5595. fread(&rchorus_feedback, sizeof(float ),1,in);
  5596. fread(&shuffle, sizeof(int),1,in);
  5597.  
  5598. // Reading track part sequence
  5599. for (int tps_pos=0;tps_pos<256;tps_pos++){for (int tps_trk=0;tps_trk<16;tps_trk++){fread(&SACTIVE[tps_pos][tps_trk],sizeof(bool),1,in);}}
  5600.  
  5601. for (int spl=0;spl<MAX_TRACKS;spl++)
  5602.     CCoef[spl]=float((float)CSend[spl]/127.0);
  5603.  
  5604. for (twrite=0;twrite<MAX_TRACKS;twrite++)
  5605. fread(&TRACKMIDICHANNEL[twrite], sizeof(int),1,in);
  5606.  
  5607. for (twrite=0;twrite<MAX_TRACKS;twrite++)
  5608. {
  5609. fread(&LFO_ON[twrite], sizeof(char),1,in);
  5610. fread(&LFORATE[twrite], sizeof(float),1,in);
  5611. fread(&LFOAMPL[twrite], sizeof(float),1,in);
  5612. }
  5613.  
  5614. for (twrite=0;twrite<MAX_TRACKS;twrite++){
  5615. fread(&FLANGER_ON[twrite], sizeof(char),1,in);
  5616. fread(&FLANGER_AMOUNT[twrite], sizeof(float),1,in);
  5617. fread(&FLANGER_DEPHASE[twrite], sizeof(float),1,in);
  5618. fread(&FLANGER_RATE[twrite], sizeof(float),1,in);
  5619. fread(&FLANGER_AMPL[twrite], sizeof(float),1,in);
  5620. fread(&FLANGER_FEEDBACK[twrite], sizeof(float),1,in);
  5621. fread(&FLANGER_DELAY[twrite], sizeof(int),1,in);
  5622. FLANGER_OFFSET[twrite]=8192;
  5623. foff2[twrite]=float(FLANGER_OFFSET[twrite]-FLANGER_DELAY[twrite]);
  5624. foff1[twrite]=float(FLANGER_OFFSET[twrite]-FLANGER_DELAY[twrite]);
  5625. }
  5626. fread(&FLANGER_DEPHASE, sizeof(float),1,in);
  5627.  
  5628. for (char tps_trk=0;tps_trk<16;tps_trk++)
  5629. fread(&TRACKSTATE[tps_trk],sizeof(int),1,in);
  5630.  
  5631. fread(&Songtracks,sizeof(char),1,in);
  5632.  
  5633. for (tps_trk=0;tps_trk<16;tps_trk++)
  5634. {
  5635. fread(&Disclap[tps_trk],sizeof(bool),1,in);
  5636. fread(&Dispan[tps_trk],sizeof(bool),1,in);
  5637. }
  5638.  
  5639. fread(artist, sizeof( char ), 20,in);
  5640. fread(style, sizeof( char ), 20,in);
  5641. fread(&QUALITYPLAY, sizeof( char ), 1,in);
  5642. fread(beatsync,sizeof(bool),128,in);
  5643. fread(beatlines,sizeof(short),128,in);
  5644. fread(&REVERBFILTER,sizeof(float),1,in);
  5645.  
  5646. fread(CustomVol,sizeof(float),128,in);
  5647. fread(&AMIMODE,sizeof(bool),1,in);
  5648. fread(&tb303,sizeof(para303),2,in);
  5649. fread(&tb303engine[0].tbVolume,sizeof(float),1,in);
  5650. fread(&tb303engine[1].tbVolume,sizeof(float),1,in);
  5651. fread(&tb303engine[0].hpf,sizeof(bool),1,in);
  5652. fread(&tb303engine[1].hpf,sizeof(bool),1,in);
  5653. fclose(in);
  5654.  
  5655. ped_track=0;
  5656. ped_patsam=1;
  5657. ped_row=0;
  5658. ped_line=0;
  5659. cPosition=0;
  5660. gui_track=0;
  5661. lchorus_counter=44100;
  5662. rchorus_counter=44100;
  5663. lchorus_counter2=44100-lchorus_delay;
  5664. rchorus_counter2=44100-rchorus_delay;
  5665. Initreverb();
  5666.  
  5667. if(userscreen!=8)
  5668. {userscreen=0;draw_mained();Actualize_Main_Ed();}
  5669. if(QUALITYPLAY==0)mess_box("NTK Level 2 Song File loaded [All Features Enabled, Hi CPU usage]");
  5670. if(QUALITYPLAY==1)mess_box("NTK Level 1 Song File loaded [CSynth: Off, Flanger Engine: Off, Medium CPU usage]");
  5671. if(QUALITYPLAY==2)mess_box("NTK Level 0 Song File loaded [Standard 16 Channel Mod, No Effects, Low CPU usage]");
  5672.  
  5673. Actualize_Sequencer();
  5674. Actualize_Patterned();
  5675. Actualize_Master(0);
  5676. Actualize_Master(4);
  5677. }
  5678. else
  5679. {
  5680. mess_box("That file is not a NoiseTrekker song-file...");
  5681. }
  5682. }
  5683. else
  5684. {
  5685. mess_box("Module loading failed. (Probably: file not found)");
  5686. }
  5687.  
  5688. if (snamesel==1 || snamesel==4 || snamesel==5)
  5689. {
  5690.     snamesel=0;
  5691.     if(userscreen!=8)Actualize_Main_Ed();
  5692. }
  5693.  
  5694. }
  5695.  
  5696. float filter2p(char ch,float input,float f,float q)
  5697. {
  5698.   f*=0.0078125f;
  5699.   q*=0.0078125f;
  5700.  
  5701.   float fa = float(1.0 - f); 
  5702.   float fb = float(q * (1.0 + (1.0/fa)));
  5703.   buf0[ch] = fa * buf0[ch] + f * (input + fb * (buf0[ch] - buf1[ch])); 
  5704.   buf1[ch] = fa * buf1[ch] + f * buf0[ch];
  5705.   return buf1[ch];  
  5706. }
  5707.  
  5708.  
  5709. float filterhp2(char ch,float input,float f,float q)
  5710. {  
  5711.   f*=0.0078125f;
  5712.   q*=0.0078125f;
  5713.  
  5714.   float fa = float(1.0 - f); 
  5715.   float fb = float(q * (1.0 + (1.0/fa)));
  5716.   buf024[ch] = fa * buf024[ch] + f * (input + fb * (buf024[ch] - buf124[ch])); 
  5717.   buf124[ch] = fa * buf124[ch] + f * buf024[ch];
  5718.   return input-buf124[ch];  
  5719. }
  5720.  
  5721. float filterhp(char ch,float input,float f,float q)
  5722. {
  5723.   f*=0.0078125f;
  5724.   q*=0.0078125f;
  5725.   float fa = float(1.0 - f); 
  5726.   float fb = float(q * (1.0 + (1.0/fa)));
  5727.   buf0[ch] = fa * buf0[ch] + f * (input + fb * (buf0[ch] - buf1[ch])); 
  5728.   buf1[ch] = fa * buf1[ch] + f * buf0[ch];
  5729.   return input-buf1[ch];  
  5730. }
  5731.  
  5732. float filter2p24d(char ch,float input,float f,float q)
  5733. {
  5734.   f*=0.0078125f;
  5735.   q*=0.0078125f;
  5736.   float fa = float(1.0 - f); 
  5737.   float fb = float(q * (1.0 + (1.0/fa)));
  5738.   buf024[ch] = fa * buf024[ch] + f * (input + fb * (buf024[ch] - buf124[ch])); 
  5739.   buf124[ch] = fa * buf124[ch] + f * buf024[ch];
  5740.   return buf124[ch];  
  5741. }
  5742.  
  5743.  
  5744. void Actualize_Songname(int newletter, char *nam)
  5745. {
  5746. if (newletter==39 && namesize>0){snamesel=0;return;}
  5747.  
  5748. if (namesize>18 && newletter!=37)return;
  5749. if (namesize==0 && newletter==37)return;
  5750.  
  5751. if (newletter!=37)namesize++;
  5752.  
  5753. switch (newletter)
  5754. {
  5755. case 1: sprintf(nam,"%sa",nam);break;
  5756. case 2: sprintf(nam,"%sb",nam);break;
  5757. case 3: sprintf(nam,"%sc",nam);break;
  5758. case 4: sprintf(nam,"%sd",nam);break;
  5759. case 5: sprintf(nam,"%se",nam);break;
  5760. case 6: sprintf(nam,"%sf",nam);break;
  5761. case 7: sprintf(nam,"%sg",nam);break;
  5762. case 8: sprintf(nam,"%sh",nam);break;
  5763. case 9: sprintf(nam,"%si",nam);break;
  5764. case 10: sprintf(nam,"%sj",nam);break;
  5765. case 11: sprintf(nam,"%sk",nam);break;
  5766. case 12: sprintf(nam,"%sl",nam);break;
  5767. case 13: sprintf(nam,"%sm",nam);break;
  5768. case 14: sprintf(nam,"%sn",nam);break;
  5769. case 15: sprintf(nam,"%so",nam);break;
  5770. case 16: sprintf(nam,"%sp",nam);break;
  5771. case 17: sprintf(nam,"%sq",nam);break;
  5772. case 18: sprintf(nam,"%sr",nam);break;
  5773. case 19: sprintf(nam,"%ss",nam);break;
  5774. case 20: sprintf(nam,"%st",nam);break;
  5775. case 21: sprintf(nam,"%su",nam);break;
  5776. case 22: sprintf(nam,"%sv",nam);break;
  5777. case 23: sprintf(nam,"%sw",nam);break;
  5778. case 24: sprintf(nam,"%sx",nam);break;
  5779. case 25: sprintf(nam,"%sy",nam);break;
  5780. case 26: sprintf(nam,"%sz",nam);break;
  5781. case 27: sprintf(nam,"%s0",nam);break;
  5782. case 28: sprintf(nam,"%s1",nam);break;
  5783. case 29: sprintf(nam,"%s2",nam);break;
  5784. case 30: sprintf(nam,"%s3",nam);break;
  5785. case 31: sprintf(nam,"%s4",nam);break;
  5786. case 32: sprintf(nam,"%s5",nam);break;
  5787. case 33: sprintf(nam,"%s6",nam);break;
  5788. case 34: sprintf(nam,"%s7",nam);break;
  5789. case 35: sprintf(nam,"%s8",nam);break;
  5790. case 36: sprintf(nam,"%s9",nam);break;
  5791. case 37: nam[strlen(nam)-1]='\0';namesize--;break;
  5792. case 38: sprintf(nam,"%s ",nam);break;
  5793. case 40: sprintf(nam,"%s.",nam);break;
  5794. case 41: sprintf(nam,"%sA",nam);break;
  5795. case 42: sprintf(nam,"%sB",nam);break;
  5796. case 43: sprintf(nam,"%sC",nam);break;
  5797. case 44: sprintf(nam,"%sD",nam);break;
  5798. case 45: sprintf(nam,"%sE",nam);break;
  5799. case 46: sprintf(nam,"%sF",nam);break;
  5800. case 47: sprintf(nam,"%sG",nam);break;
  5801. case 48: sprintf(nam,"%sH",nam);break;
  5802. case 49: sprintf(nam,"%sI",nam);break;
  5803. case 50: sprintf(nam,"%sJ",nam);break;
  5804. case 51: sprintf(nam,"%sK",nam);break;
  5805. case 52: sprintf(nam,"%sL",nam);break;
  5806. case 53: sprintf(nam,"%sM",nam);break;
  5807. case 54: sprintf(nam,"%sN",nam);break;
  5808. case 55: sprintf(nam,"%sO",nam);break;
  5809. case 56: sprintf(nam,"%sP",nam);break;
  5810. case 57: sprintf(nam,"%sQ",nam);break;
  5811. case 58: sprintf(nam,"%sR",nam);break;
  5812. case 59: sprintf(nam,"%sS",nam);break;
  5813. case 60: sprintf(nam,"%sT",nam);break;
  5814. case 61: sprintf(nam,"%sU",nam);break;
  5815. case 62: sprintf(nam,"%sV",nam);break;
  5816. case 63: sprintf(nam,"%sW",nam);break;
  5817. case 64: sprintf(nam,"%sX",nam);break;
  5818. case 65: sprintf(nam,"%sY",nam);break;
  5819. case 66: sprintf(nam,"%sZ",nam);break;
  5820. case 67: sprintf(nam,"%s,",nam);break;
  5821. case 68: sprintf(nam,"%s-",nam);break;
  5822. case 69: sprintf(nam,"%s'",nam);break;
  5823. case 70: sprintf(nam,"%sí",nam);break;
  5824. }
  5825. }
  5826.  
  5827. void Newmod(void)
  5828. {
  5829. guiDial(90,350,80,16,"New Song",100);
  5830. SongStop();
  5831. mess_box("Freeing all allocated buffers and restarting...");    
  5832. Sleep(1000);
  5833.  
  5834. FreeAll();
  5835. init_sample_bank();
  5836.  
  5837. for (int api=0;api<128;api++)
  5838. patternLines[api]=64;
  5839.  
  5840. for (int inicial=0;inicial<PBLEN;inicial+=6)
  5841. {
  5842. *(RawPatterns+inicial)=121;//121
  5843. *(RawPatterns+inicial+1)=255;//255
  5844. *(RawPatterns+inicial+2)=255;//255
  5845. *(RawPatterns+inicial+3)=255;//255
  5846. *(RawPatterns+inicial+4)=0;//0
  5847. *(RawPatterns+inicial+5)=0;//0
  5848. }
  5849.  
  5850. nPatterns=1;
  5851. Iniplayer();
  5852. sprintf(name,"Untitled");
  5853. sprintf(artist,"Somebody");
  5854. sprintf(style,"Goa Trance");
  5855. namesize=8;
  5856. sLength=1;
  5857. BeatsPerMin=125;
  5858. TicksPerBeat=4;
  5859. SamplesPerSec=44100;
  5860. SubCounter=0;
  5861. PosInTick=0;
  5862. DelayType=1;
  5863. player_line=0;
  5864. mas_vol=1.0f;
  5865. ped_track=0;
  5866. ped_patsam=1;
  5867. ped_row=0;
  5868. ped_line=0;
  5869. cPosition=0;
  5870.  
  5871. lchorus_feedback=0.6f;
  5872. rchorus_feedback=0.5f;
  5873. lchorus_delay=10584;
  5874. rchorus_delay=15876;
  5875.  
  5876. lchorus_counter=44100;
  5877. rchorus_counter=44100;
  5878. lchorus_counter2=44100-lchorus_delay;
  5879. rchorus_counter2=44100-rchorus_delay;
  5880. compressor=0;
  5881. c_threshold=32;
  5882. DelayType=1;
  5883. delay_time=0;
  5884. seditor=0;
  5885.  
  5886. for (int spl=0;spl<MAX_TRACKS;spl++)
  5887. CCoef[spl]=float((float)CSend[spl]/127.0);
  5888.  
  5889. Actualize_Sequencer();
  5890. Actualize_Patterned();
  5891. Actualize_Master(0);
  5892. if (snamesel==1 || snamesel==4 || snamesel==5)snamesel=0;
  5893. Actualize_Main_Ed();
  5894.  
  5895. mess_box("New song started...");
  5896. Sleep(300);
  5897. guiDial(90,350,80,16,"New Song",200);
  5898. NewWavy();
  5899. S->copy(FRAMEWORK, 0, 184);
  5900. Actupated(0);
  5901. }
  5902.  
  5903. void draw_seqed(void)
  5904. {
  5905. guiDial(112,309,64,16,"Track FX",200);
  5906. guiDial(178,309,64,16,"Midi/CSynth",200);
  5907. guiDial(244,309,64,16,"Master",200);
  5908. guiDial(310,309,64,16,"Sequencer",100);
  5909. guiDial(376,309,64,16,"Disk IO",200);
  5910. guiDial(442,309,64,16,"Track",200);
  5911. guiDial(508,309,64,16,"Instrument",200);
  5912. guiDial(574,309,64,16,"FX Setup",200);
  5913. guiDial(640,309,64,16,"Extend Edit",200);
  5914. guiDial(706,309,64,16,"303",200);
  5915.  
  5916. guiDial2("Track Part Sequencer / Stereo Scope");
  5917. guiDial3(4,348,134,86,"Left Scope",100);
  5918. guiDial3(496,348,134,86,"Right Scope",100);
  5919. guiDial(144,348,80,16,"Clear All",200);
  5920. guiDial(144,366,80,16,"Clear Position",200);
  5921. guiDial(144,384,80,16,"Reset All",200);
  5922. guiDial(144,402,80,16,"Reset Position",200);
  5923. guiDial(410,348,80,16,"Ptn->Pos[Cur]",200);
  5924. guiDial(410,366,80,16,"Ptn->Pos[Sng]",200);
  5925.  
  5926. guiDial3(144,420,32,16,"Scop.",200);
  5927. guiDial(230,343,14,88,"",200);
  5928. guiDial(390,343,14,88,"",200);
  5929. guiDial(254,343,128,88,"",200);
  5930. S->setColor(0,0,0);
  5931. bjbox(257,346,124,86);
  5932. S->setColor(0,80,0);
  5933. bjbox(257,382,124,12);
  5934. Actualize_Scopish();
  5935. }
  5936.  
  5937. void Actualize_Scopish(void)
  5938. {
  5939. if (Scopish)
  5940. {
  5941. guiDial(178,420,22,16,"On",100);
  5942. guiDial(202,420,22,16,"Off",200);
  5943. }
  5944. else
  5945. {
  5946. guiDial(178,420,22,16,"On",200);
  5947. guiDial(202,420,22,16,"Off",100);
  5948. }
  5949. }
  5950.  
  5951. void Actualize_Seq_Ed(void)
  5952. {
  5953. mess_box("Ready...");
  5954. HDC dc=(HDC)S->getDeviceContext();
  5955. SetBkMode(dc,OPAQUE);
  5956.  
  5957. for (int lseq=-3;lseq<4;lseq++)
  5958.     {
  5959.                     if (lseq==0)
  5960.                         S->setBKColor(0,80,0);
  5961.                     else
  5962.                         S->setBKColor(0,10,0);
  5963.  
  5964.       int rel=lseq+cPosition;
  5965.       if (rel>-1 && rel<256)
  5966.             {
  5967.                 out_decchar(232,382+lseq*12,rel,0);
  5968.                 out_decchar(392,382+lseq*12,pSequence[rel],0);
  5969.  
  5970.                 for (int rel2=0;rel2<Songtracks;rel2++)
  5971.                 {
  5972.                     
  5973.                     if (SACTIVE[rel][rel2])
  5974.                     out_nibble(256+rel2*8,382+lseq*12,0x20F040,rel2);
  5975.                     else
  5976.                     out_nibble(256+rel2*8,382+lseq*12,0x205030,rel2);
  5977.                 
  5978.                 }//sub for
  5979.             }// rel range OK
  5980.             else
  5981.             {
  5982.                 S->printXY(256,382+lseq*12,0x000000,"000000000000000000000");
  5983.                 S->printXY(232,382+lseq*12,0x000000,"00");
  5984.                 S->printXY(392,382+lseq*12,0x000000,"00");
  5985.                     
  5986.             }
  5987.     }// for end
  5988. SetBkMode(dc,TRANSPARENT);
  5989. Actupated(0);
  5990. }
  5991.  
  5992. void out_nibble(int x,int y,int color, int number)
  5993. {
  5994. switch(number)
  5995. {
  5996. case 0: S->printXY(x,y, color,"0");break;
  5997. case 1: S->printXY(x,y, color,"1");break;
  5998. case 2: S->printXY(x,y, color,"2");break;
  5999. case 3: S->printXY(x,y, color,"3");break;
  6000. case 4: S->printXY(x,y, color,"4");break;
  6001. case 5: S->printXY(x,y, color,"5");break;
  6002. case 6: S->printXY(x,y, color,"6");break;
  6003. case 7: S->printXY(x,y, color,"7");break;
  6004. case 8: S->printXY(x,y, color,"8");break;
  6005. case 9: S->printXY(x,y, color,"9");break;
  6006. case 10: S->printXY(x,y, color,"A");break;
  6007. case 11: S->printXY(x,y, color,"B");break;
  6008. case 12: S->printXY(x,y, color,"C");break;
  6009. case 13: S->printXY(x,y, color,"D");break;
  6010. case 14: S->printXY(x,y, color,"E");break;
  6011. case 15: S->printXY(x,y, color,"F");break;
  6012. }
  6013. }
  6014.  
  6015. void Resetdevice()
  6016. {
  6017. if (ss!=NULL)
  6018.  {
  6019.     if (ss->isPlaying())
  6020.     {
  6021.     ss->stop();
  6022.     ss->setStreamDelay(XLATENCY_TIME);
  6023.     ss->play();    
  6024.     }
  6025.   }
  6026. }
  6027.  
  6028. void draw_mastered(void)
  6029. {
  6030. guiDial(112,309,64,16,"Track FX",200);
  6031. guiDial(178,309,64,16,"Midi/CSynth",200);
  6032. guiDial(244,309,64,16,"Master",100);
  6033. guiDial(310,309,64,16,"Sequencer",200);
  6034. guiDial(376,309,64,16,"Disk IO",200);
  6035. guiDial(442,309,64,16,"Track",200);
  6036. guiDial(508,309,64,16,"Instrument",200);
  6037. guiDial(574,309,64,16,"FX Setup",200);
  6038. guiDial(640,309,64,16,"Extend Edit",200);
  6039. guiDial(706,309,64,16,"303",200);
  6040.  
  6041. guiDial2("Master configuration / Info");
  6042.  
  6043. guiDial3(8,420,42,16,"Shuffle",200);
  6044. guiDial3(190,366,60,16,"Master Vol",200);
  6045. guiDial3(190,384,60,16,"09xx Mode",200);
  6046.  
  6047. Coolwrite(216,334,0x00FFFFFF,"Beats Per Min:");
  6048. Coolwrite(400,334,0x00FFFFFF,"1/4 Beat Time:");
  6049. Coolwrite(8,405,0x00FFFFFF,"Shuffle effect amount:");
  6050. }
  6051.  
  6052. void Actualize_Master_Ed(char gode)
  6053. {
  6054. if(userscreen==5)
  6055. {
  6056.  
  6057. if (gode==0 || gode==2)
  6058. {
  6059. if (mas_vol<0.01f)mas_vol=0.01f;
  6060. if (mas_vol>1.0f)mas_vol=1.0f;
  6061. Realslider(252,366,f2i(mas_vol*128));
  6062. outlong(401,366,f2i(mas_vol*100),1);
  6063. }
  6064.  
  6065. if (gode==0 || gode==3)
  6066. {
  6067. outlong(292,332,BeatsPerMin,0);
  6068. outlong(476,332,f2i(15000/(float)BeatsPerMin),2);
  6069. }
  6070.  
  6071. if (gode==0 || gode==4)
  6072. {
  6073. if (shuffle>100)shuffle=100;
  6074. if (shuffle<0)shuffle=0;
  6075. Realslider(52,420,shuffle);
  6076. outlong(201,420,shuffle,1);
  6077. }
  6078.  
  6079. if (gode==0 || gode==5)
  6080. {
  6081. if(AMIMODE)
  6082. {
  6083. guiDial(252,384,46,16,"Mod",100);
  6084. guiDial(300,384,46,16,"Ntk",200);
  6085. }else{
  6086. guiDial(252,384,46,16,"Mod",200);
  6087. guiDial(300,384,46,16,"Ntk",100);
  6088. }
  6089.  
  6090. }
  6091.  
  6092. }
  6093. }
  6094.  
  6095.  
  6096.  
  6097.  
  6098. void SaveSettings()
  6099. {
  6100. _chdir(appbuffer);
  6101.  
  6102. FILE *in;
  6103. in = fopen("ntk.cfg","wb");
  6104. if (in!=NULL)
  6105. {
  6106. // Writing noisetrekker configuration
  6107. fwrite(&XLATENCY_TIME, sizeof(int),1,in);
  6108. fwrite(&CONSOLE_WIDTH, sizeof(int),1,in);
  6109. fwrite(&CONSOLE_HEIGHT, sizeof(int),1,in);
  6110. fwrite(&GUIMODE, sizeof(char),1,in);
  6111. fwrite(&Scopish, sizeof(bool),1,in);
  6112. fclose(in);
  6113. }
  6114. }
  6115.  
  6116. void LoadSettings()
  6117. {
  6118. FILE *in;
  6119.  
  6120.   /* Get the current working directory: */
  6121. _getcwd(appbuffer, _MAX_PATH );
  6122.  
  6123. in = fopen("ntk.cfg","rb");
  6124. if (in!=NULL)
  6125. {
  6126. // Reading NoiseTrekker header & name...
  6127. fread(&XLATENCY_TIME, sizeof(int),1,in);
  6128. fseek(in,sizeof(int)*2,SEEK_CUR); // Ignore videomode;
  6129. fread(&GUIMODE, sizeof(char),1,in);
  6130. fread(&Scopish, sizeof(bool),1,in);
  6131.  
  6132. fclose(in);
  6133. }
  6134. }
  6135.  
  6136. void DrawScope(void)
  6137. {
  6138. int xl=8;
  6139. int xr=500;
  6140.  
  6141. for (int s=0;s<128;s++)
  6142. {
  6143. int yl=400-Lscope[s]/1024;
  6144. int yr=400-Rscope[s]/1024;
  6145.  
  6146. S->drawLine(xl,yl,xl,yl,0xFFFF);
  6147. S->drawLine(xr,yr,xr,yr,0xFFFF);
  6148.  
  6149. S->drawLine(xl,368,xl,yl-1,0);
  6150. S->drawLine(xr,368,xr,yr-1,0);
  6151.  
  6152. S->drawLine(xl,yl+1,xl,432,yl);
  6153. S->drawLine(xr,yr+1,xr,432,yr);
  6154. xl++;
  6155. xr++;
  6156. }
  6157.  
  6158. }
  6159.  
  6160. void MidiGetAll(void)
  6161. {
  6162. n_midiindevices=midiInGetNumDevs();
  6163. n_midioutdevices=midiOutGetNumDevs();
  6164.  
  6165. for (int m=0;m<n_midiindevices;m++)
  6166.     midiInGetDevCaps(m,&caps_midiin[m],sizeof(MIDIINCAPS));
  6167.  
  6168. for (m=0;m<n_midioutdevices;m++)
  6169.     midiOutGetDevCaps(m,&caps_midiout[m],sizeof(MIDIOUTCAPS));
  6170. }
  6171.  
  6172. void draw_midied(void)
  6173. {
  6174. guiDial(112,309,64,16,"Track FX",200);
  6175. guiDial(178,309,64,16,"Midi/CSynth",100);
  6176. guiDial(244,309,64,16,"Master",200);
  6177. guiDial(310,309,64,16,"Sequencer",200);
  6178. guiDial(376,309,64,16,"Disk IO",200);
  6179. guiDial(442,309,64,16,"Track",200);
  6180. guiDial(508,309,64,16,"Instrument",200);
  6181. guiDial(574,309,64,16,"FX Setup",200);
  6182. guiDial(640,309,64,16,"Extend Edit",200);
  6183. guiDial(706,309,64,16,"303",200);
  6184.  
  6185. char middev[80];
  6186.  
  6187. sprintf(middev,"Midi Setup. Found: %d Midi-In devices and %d Midi-Out devices.",n_midiindevices,n_midioutdevices);
  6188. guiDial2("");
  6189. guiDial3(4,336,332,108,middev,128);
  6190.  
  6191. guiDial3(8,352,56,16,"Midi IN",200);
  6192. guiDial3(8,370,56,16,"Midi OUT",200);
  6193. guiDial(8,388,124,16,"All Notes Off (Track)",200);
  6194. guiDial(134,388,124,16,"All Notes Off (Song)",200);
  6195. guiDial3(340,336,296,108,"Instrument [Synthesizer Editor - CSynth]",128);
  6196. guiDial3(348,352,56,16,"Program",200);
  6197. guiDial3(348,370,56,16,"Parameter",200);
  6198. guiDial3(348,388,38,16,"Value",200);
  6199. guiDial3(348,406,38,16,"OSC1",200);
  6200. guiDial3(348,424,38,16,"OSC2",200);
  6201. guiDial3(518,406,52,16,"Sub OSC",200);
  6202. guiDial3(518,424,52,16,"VCF Type",200);
  6203. guiDial(598,352,34,16,"Save",200);
  6204. guiDial(598,370,34,16,"Rand",200);
  6205.  
  6206. guiDial(388,388,16,16,"<",220);
  6207. guiDial(554,388,16,16,">",220);
  6208.  
  6209. S->printXY(7,424,0x00000000,"Go to 'Track' section to assign Midi Channels to NoiseTrekker tracks");
  6210. S->printXY(8,423,0x00FFFFFF,"Go to 'Track' section to assign Midi Channels to NoiseTrekker tracks");
  6211. }
  6212.  
  6213. void Actualize_Midi_Ed(char gode)
  6214. {
  6215.  
  6216. if (gode==0 || gode==1)
  6217. {
  6218. valuer_box4(406,352,ped_patsam);
  6219. Actualize_SynthParSlider();
  6220. }
  6221.  
  6222. if (gode==6)
  6223. {
  6224. CParcha(csynth_slv);
  6225. Actualize_SynthParSlider();
  6226. }
  6227.  
  6228. if (gode==0 || gode==10 || gode==1)
  6229. {
  6230. char tcp[30];
  6231. sprintf(tcp,"%s_",PARASynth[ped_patsam].presetname);
  6232.  
  6233. if (snamesel==3)
  6234. guiDial(432,352,164,16,tcp,100);
  6235. else
  6236. guiDial(432,352,164,16,PARASynth[ped_patsam].presetname,140);
  6237. }
  6238.  
  6239. if (gode==0 || gode==2)
  6240. {
  6241. if (ped_synthpar<1)ped_synthpar=1;
  6242. if (ped_synthpar>51)ped_synthpar=51;
  6243. valuer_box2(406,370,ped_synthpar);
  6244. guiDial3(468,370,128,16,CS_PAR_NAME[ped_synthpar],140);
  6245. Actualize_SynthParSlider();
  6246. }
  6247.  
  6248. if (gode==0 || gode==3 || gode==1)
  6249. {
  6250. guiDial(388,406,24,16,"Sin",140);
  6251. guiDial(414,406,24,16,"Saw",140);
  6252. guiDial(440,406,24,16,"Pul",140);
  6253. guiDial(466,406,24,16,"Rnd",140);
  6254. guiDial(492,406,24,16,"Off",140);
  6255. switch (PARASynth[ped_patsam].osc1_waveform)
  6256. {
  6257. case 0:guiDial(388,406,24,16,"Sin",100);break;
  6258. case 1:guiDial(414,406,24,16,"Saw",100);break;
  6259. case 2:guiDial(440,406,24,16,"Pul",100);break;
  6260. case 3:guiDial(466,406,24,16,"Rnd",100);break;
  6261. case 4:guiDial(492,406,24,16,"Off",100);break;
  6262. }
  6263. }
  6264.  
  6265. if (gode==0 || gode==4 || gode==1)
  6266. {
  6267. guiDial(388,424,24,16,"Sin",140);
  6268. guiDial(414,424,24,16,"Saw",140);
  6269. guiDial(440,424,24,16,"Pul",140);
  6270. guiDial(466,424,24,16,"Rnd",140);
  6271. guiDial(492,424,24,16,"Off",140);
  6272. switch (PARASynth[ped_patsam].osc2_waveform)
  6273. {
  6274. case 0:guiDial(388,424,24,16,"Sin",100);break;
  6275. case 1:guiDial(414,424,24,16,"Saw",100);break;
  6276. case 2:guiDial(440,424,24,16,"Pul",100);break;
  6277. case 3:guiDial(466,424,24,16,"Rnd",100);break;
  6278. case 4:guiDial(492,424,24,16,"Off",100);break;
  6279. }
  6280. }
  6281.  
  6282. if (gode==0 || gode==5 || gode==1)
  6283. {
  6284.     if (PARASynth[ped_patsam].osc3_switch)
  6285.     {
  6286.     guiDial(572,406,24,16,"On",100);
  6287.     guiDial(596,406,24,16,"Off",200);
  6288.     }else{
  6289.     guiDial(572,406,24,16,"On",200);
  6290.     guiDial(596,406,24,16,"Off",100);
  6291.     }
  6292. }
  6293.  
  6294. if (gode==0 || gode==7 || gode==1)
  6295. {
  6296.     valuer_box(572,424,PARASynth[ped_patsam].vcf_type);
  6297. }
  6298.  
  6299. if (midiin_changed==true)
  6300. {
  6301. if (c_midiin<-1)c_midiin=n_midiindevices-1;
  6302. if (c_midiin==n_midiindevices)c_midiin=-1;
  6303.  
  6304. if (c_midiin!=-1){
  6305. if (midiin_handle!=NULL)midiInClose(midiin_handle);
  6306. if (midiInOpen(&midiin_handle,c_midiin, NULL, NULL,CALLBACK_NULL)==MMSYSERR_NOERROR)
  6307. mess_box("Midi In device actived...");
  6308. else
  6309. mess_box("Midi In device failed...");
  6310. }
  6311. else
  6312. mess_box("Midi In disconnected...");
  6313.  
  6314. midiin_changed=false;
  6315. }
  6316.  
  6317. if (midiout_changed==true)
  6318. {
  6319. MidiReset();
  6320. if (c_midiout<-1)c_midiout=n_midioutdevices-1;
  6321. if (c_midiout==n_midioutdevices)c_midiout=-1;
  6322.  
  6323. if (c_midiout!=-1){
  6324. if (midiout_handle!=NULL)midiOutClose(midiout_handle);
  6325. if (midiOutOpen(&midiout_handle,c_midiout, NULL, NULL,CALLBACK_NULL)==MMSYSERR_NOERROR)
  6326. mess_box("Midi Out device actived...");
  6327. else
  6328. mess_box("Midi Out device failed...");
  6329. }
  6330. else
  6331. mess_box("Midi Out disconnected...");
  6332.  
  6333. midiout_changed=false;
  6334. }
  6335.  
  6336. if (gode==0 || gode==8)
  6337. {
  6338. valuer_box(66,352,c_midiin+1);
  6339. if (c_midiin!=-1)
  6340. guiDial3(128,352,192,16,caps_midiin[c_midiin].szPname,100);
  6341. else
  6342. guiDial3(128,352,192,16,"None",100);
  6343. }
  6344.  
  6345. if (gode==0 || gode==9)
  6346. {
  6347. valuer_box(66,370,c_midiout+1);
  6348. if (c_midiout!=-1)
  6349. guiDial3(128,370,192,16,caps_midiout[c_midiout].szPname,100);
  6350. else
  6351. guiDial3(128,370,192,16,"None",100);
  6352. }
  6353.  
  6354. }
  6355.  
  6356. void GetPlayerValues(float master_coef)
  6357. {
  6358. left_chorus=2.0f;
  6359. right_chorus=2.0f;
  6360. Sp_Player();
  6361. if (++lchorus_counter>88200)lchorus_counter=44100;
  6362. if (++rchorus_counter>88200)rchorus_counter=44100;
  6363. lbuff_chorus[lchorus_counter]=left_chorus+lbuff_chorus[lchorus_counter2]*lchorus_feedback;
  6364. rbuff_chorus[rchorus_counter]=right_chorus+rbuff_chorus[rchorus_counter2]*rchorus_feedback;
  6365. if (++lchorus_counter2>88200)lchorus_counter2=44100;
  6366. if (++rchorus_counter2>88200)rchorus_counter2=44100;
  6367. float rchore=lbuff_chorus[lchorus_counter2];
  6368. float lchore=rbuff_chorus[rchorus_counter2];
  6369. left_float=lchore+left_float;    
  6370. right_float=rchore+right_float;
  6371. Compressor_work();
  6372.  
  6373. left_value=f2i(left_float*master_coef);
  6374. right_value=f2i(right_float*master_coef);
  6375.  
  6376. if (left_value>32767)left_value=32767;
  6377. if (left_value<-32767)left_value=-32767;
  6378. if (right_value>32767)right_value=32767;
  6379. if (right_value<-32767)right_value=-32767;
  6380. }
  6381.  
  6382. void GetPlayerValues2(float master_coef)
  6383. {
  6384. left_chorus=2.0f;
  6385. right_chorus=2.0f;
  6386. Sp_Player2();
  6387. if (++lchorus_counter>88200)lchorus_counter=44100;
  6388. if (++rchorus_counter>88200)rchorus_counter=44100;
  6389. lbuff_chorus[lchorus_counter]=left_chorus+lbuff_chorus[lchorus_counter2]*lchorus_feedback;
  6390. rbuff_chorus[rchorus_counter]=right_chorus+rbuff_chorus[rchorus_counter2]*rchorus_feedback;
  6391. if (++lchorus_counter2>88200)lchorus_counter2=44100;
  6392. if (++rchorus_counter2>88200)rchorus_counter2=44100;
  6393. float rchore=lbuff_chorus[lchorus_counter2];
  6394. float lchore=rbuff_chorus[rchorus_counter2];
  6395. left_float=lchore+left_float;    
  6396. right_float=rchore+right_float;
  6397. Compressor_work();
  6398. left_value=f2i(left_float*master_coef);
  6399. right_value=f2i(right_float*master_coef);
  6400. if (left_value>32767)left_value=32767;
  6401. if (left_value<-32767)left_value=-32767;
  6402. if (right_value>32767)right_value=32767;
  6403. if (right_value<-32767)right_value=-32767;
  6404. }
  6405.  
  6406. void GetPlayerValues3(float master_coef)
  6407. {
  6408. Sp_Player3();
  6409. left_value=f2i(left_float*master_coef);
  6410. right_value=f2i(right_float*master_coef);
  6411. if (left_value>32767)left_value=32767;
  6412. if (left_value<-32767)left_value=-32767;
  6413. if (right_value>32767)right_value=32767;
  6414. if (right_value<-32767)right_value=-32767;
  6415. }
  6416.  
  6417. void RawRenderizer(void)
  6418. {
  6419. plx=0;
  6420. char buffer[80];
  6421. sprintf(buffer,"%s.wav",name);
  6422.  
  6423. if (!hd_isrecording)
  6424. {
  6425. WaveFile RF;
  6426. RF.OpenForWrite (buffer,44100,16,2);
  6427. guiDial(90,368,80,16,"WAV Render",100);
  6428. SongStop();
  6429. Sleep(500);
  6430. sprintf(buffer,"Rendering module to '%s.wav' file. Please wait...",name);
  6431. mess_box(buffer);
  6432. Sleep(500);
  6433. ped_line=0;
  6434. cPosition=0;
  6435. SongPlay();
  6436. int lastline=ped_line;
  6437. long filesize=0;
  6438. bool bru=false;
  6439. while(cPosition>0 || ped_line>0 || bru==false){
  6440. if (ped_line>0)bru=true;
  6441. GetPlayerValues(mas_vol); // <-- L INT
  6442. RF.WriteStereoSample(left_value,right_value);
  6443. filesize+=4;
  6444. if (lastline!=ped_line){
  6445. float cline=(cPosition*64.0f)+ped_line;
  6446. float tline=sLength*64.0f;
  6447. float cfr=(cline*100.0f)/tline; 
  6448. sprintf(buffer,"Rendering line %d, position %d. (%.2f%%)     File Size: %.2f Megabytes",lastline,cPosition,cfr, float(filesize/1048576.0f));
  6449. mess_box(buffer);
  6450. lastline=ped_line;
  6451. }
  6452. }
  6453.  
  6454. RF.Close();
  6455. SongStop();
  6456. int minutos=filesize/10584000;
  6457. int segundos=(filesize-minutos*10584000)/176400;
  6458.  
  6459. sprintf(buffer,"Wav Render finished. File size: %.2f Megabytes. Playback Time: %d'%d''.",float(filesize/1048576.0f),minutos,segundos);
  6460. mess_box(buffer);
  6461. ped_line=0;
  6462. cPosition=0;
  6463. Actualize_Main_Ed();
  6464.  
  6465. last_index=-1;
  6466. Read_SMPT();
  6467. ltActualize(0);
  6468.  
  6469. mess_box(buffer);
  6470. Sleep(500);
  6471. guiDial(90,368,80,16,"WAV Render",200);
  6472. Actupated(0);
  6473. }
  6474.  
  6475. rawrender=false;
  6476. }
  6477.  
  6478. void MidiAllNotesOff(void)
  6479. {
  6480. if (c_midiout!=-1)
  6481. {
  6482. for (int no_track=0;no_track<16;no_track++)
  6483. midiOutShortMsg(midiout_handle, (176+no_track) | (123 << 8) | (0 << 16)); 
  6484. }
  6485. }
  6486.  
  6487. void MidiReset(void)
  6488. {
  6489. MidiAllNotesOff();
  6490.  
  6491. for(int mreset=0;mreset<16;mreset++)
  6492. {
  6493.     LastProgram[mreset]=-1;
  6494. }
  6495.  
  6496. }
  6497.  
  6498. void draw_lfoed(void)
  6499. {
  6500. guiDial(112,309,64,16,"Track FX",100);
  6501. guiDial(178,309,64,16,"Midi/CSynth",200);
  6502. guiDial(244,309,64,16,"Master",200);
  6503. guiDial(310,309,64,16,"Sequencer",200);
  6504. guiDial(376,309,64,16,"Disk IO",200);
  6505. guiDial(442,309,64,16,"Track",200);
  6506. guiDial(508,309,64,16,"Instrument",200);
  6507. guiDial(574,309,64,16,"FX Setup",200);
  6508. guiDial(640,309,64,16,"Extend Edit",200);
  6509. guiDial(706,309,64,16,"303",200);
  6510.  
  6511. guiDial2("Track FX: Filter LFO And Flanger");
  6512. guiDial3(8,362,64,16,"Frequency",200);
  6513. guiDial3(8,380,64,16,"Amplitude",200);
  6514. guiDial3(230,334,288,110,"Flanger Settings",128);
  6515. guiDial3(238,350,56,16,"Amount",200);
  6516. guiDial3(238,368,56,16,"Period",200);
  6517. guiDial3(238,386,56,16,"Amplitude",200);
  6518. guiDial3(238,404,56,16,"Feedback",200);
  6519. guiDial3(238,422,56,16,"Delay",200);
  6520. guiDial3(8,398,64,16,"LFO Status",200);
  6521. guiDial3(8,416,64,16,"Flanger3D",200);
  6522. guiDial3(524,334,104,110,"Track Atributes",128);
  6523. guiDial3(532,350,88,16,"Panning Change",200);
  6524. }
  6525.  
  6526. void Actualize_Lfo_Ed(char gode)
  6527. {
  6528. if(userscreen==7)
  6529. {
  6530.     char tmp[16];
  6531.     if (gode==0 || gode==1){
  6532.     if (FLANGER_AMOUNT[ped_track]>1.0f)FLANGER_AMOUNT[ped_track]=1.0f;
  6533.     if (FLANGER_AMOUNT[ped_track]<-1.0f)FLANGER_AMOUNT[ped_track]=-1.0f;
  6534.     Realslider(298,350,64+f2i(FLANGER_AMOUNT[ped_track]*64.0f));
  6535.     outlong(448,350,long(FLANGER_AMOUNT[ped_track]*100.0f),1);}
  6536.  
  6537.     if (gode==0 || gode==7){
  6538.     if (FLANGER_FEEDBACK[ped_track]>1.0f)FLANGER_FEEDBACK[ped_track]=1.0f;
  6539.     if (FLANGER_FEEDBACK[ped_track]<-1.0f)FLANGER_FEEDBACK[ped_track]=-1.0f;
  6540.     Realslider(298,404,64+f2i(FLANGER_FEEDBACK[ped_track]*64.0f));
  6541.     outlong(448,404,long(FLANGER_FEEDBACK[ped_track]*100.0f),1);}
  6542.  
  6543.     if (gode==0 || gode==4){
  6544.     if (FLANGER_DEPHASE[ped_track]>3.1415927f)FLANGER_DEPHASE[ped_track]=3.1415927f;
  6545.     if (FLANGER_DEPHASE[ped_track]<0.0f)FLANGER_DEPHASE[ped_track]=0.0f;
  6546.     Realslider2(74,416,f2i(FLANGER_DEPHASE[ped_track]*20.371833f));
  6547.     outlong(158,416,f2i(FLANGER_DEPHASE[ped_track]*57.29578f),6);}
  6548.  
  6549.     if (gode==0 || gode==5){
  6550.     if (FLANGER_RATE[ped_track]<0.000001f)FLANGER_RATE[ped_track]=0.000001f;
  6551.     if (FLANGER_RATE[ped_track]>0.0001363f)FLANGER_RATE[ped_track]=0.0001363f;
  6552.     Realslider(298,368,f2i(FLANGER_RATE[ped_track]*939104.92f));
  6553.     outlong(448,368,long(0.1424758f/FLANGER_RATE[ped_track]),2);}
  6554.  
  6555.     if (gode==0 || gode==6){
  6556.     if (FLANGER_AMPL[ped_track]>0.01f)FLANGER_AMPL[ped_track]=0.01f;
  6557.     if (FLANGER_AMPL[ped_track]<0.0f)FLANGER_AMPL[ped_track]=0.0f;
  6558.     Realslider(298,386,f2i(FLANGER_AMPL[ped_track]*12800.0f));
  6559.     outlong(448,386,f2i(FLANGER_AMPL[ped_track]*10000.0f),1);
  6560.     }
  6561.  
  6562.     if (gode==0 || gode==2){
  6563.     if (LFORATE[ped_track]<0.0001f)LFORATE[ped_track]=0.0001f;
  6564.     if (LFORATE[ped_track]>0.0078125f)LFORATE[ped_track]=0.0078125f;
  6565.     Realslider(74,362,f2i(LFORATE[ped_track]*16384.0f));
  6566.     float tmprate=(8.1632653f/LFORATE[ped_track]);
  6567.     outlong(74,398,(long)tmprate,2);
  6568.     tmprate=1000.0f/tmprate;
  6569.     outfloat(136,398,tmprate,3);}
  6570.     
  6571.     if (gode==0 || gode==3){
  6572.     if (LFOAMPL[ped_track]<0)LFOAMPL[ped_track]=0;
  6573.     if (LFOAMPL[ped_track]>128)LFOAMPL[ped_track]=128;
  6574.     Realslider(74,380,f2i(LFOAMPL[ped_track]));}
  6575.     
  6576.     if (gode==0 || gode==9){
  6577.     sprintf(tmp,"Flt.LFO[%d]",ped_track);
  6578.     guiDial3(8,344,64,16,tmp,200);
  6579.     if(LFO_ON[ped_track]==1){
  6580.     guiDial(74,344,20,16,"On",100);
  6581.     guiDial(96,344,20,16,"Off",200);
  6582.     }else{
  6583.     guiDial(74,344,20,16,"On",200);
  6584.     guiDial(96,344,20,16,"Off",100);}}
  6585.  
  6586.     if (gode==0 || gode==10){
  6587.     sprintf(tmp,"Flanger[%d]",ped_track);
  6588.     guiDial3(118,344,64,16,tmp,200);
  6589.     if(FLANGER_ON[ped_track]==1){
  6590.     guiDial(184,344,20,16,"On",100);
  6591.     guiDial(206,344,20,16,"Off",200);
  6592.     }else{
  6593.     guiDial(184,344,20,16,"On",200);
  6594.     guiDial(206,344,20,16,"Off",100);}}
  6595.  
  6596.     if (gode==0 || gode==8){
  6597.     if (FLANGER_DELAY[ped_track]>4096)FLANGER_DELAY[ped_track]=4096;
  6598.     if (FLANGER_DELAY[ped_track]<0)FLANGER_DELAY[ped_track]=0;    
  6599.     if(fld_chan==true){
  6600.     FLANGER_OFFSET[ped_track]=8192;
  6601.     foff2[ped_track]=float(FLANGER_OFFSET[ped_track]-FLANGER_DELAY[ped_track]);
  6602.     foff1[ped_track]=float(FLANGER_OFFSET[ped_track]-FLANGER_DELAY[ped_track]);    
  6603.     fld_chan=false;}
  6604.     Realslider(298,422,FLANGER_DELAY[ped_track]/32);
  6605.     outlong(448,422,long(FLANGER_DELAY[ped_track]/44.1f),2);
  6606.     }
  6607.  
  6608.     if (gode==0 || gode==11)
  6609.     {
  6610.         if (Dispan[ped_track])
  6611.         {
  6612.         guiDial(532,368,42,16,"Instant.",200);
  6613.         guiDial(576,368,44,16,"Smooth",100);
  6614.         }else{
  6615.         guiDial(532,368,42,16,"Instant.",100);
  6616.         guiDial(576,368,44,16,"Smooth",200);
  6617.         }
  6618.     }
  6619.  
  6620. }//User gui screen match
  6621. }
  6622.  
  6623. float ApplyLfo(float cy,char trcy)
  6624. {
  6625.     if (LFO_ON[trcy]==1)
  6626.     {
  6627.     cy+=SIN[f2i(LFOGR[trcy])]*LFOAMPL[trcy];
  6628.     LFOGR[trcy]+=LFORATE[trcy];
  6629.     if (LFOGR[trcy]>=360)LFOGR[trcy]-=360;
  6630.     }
  6631.  
  6632.     if (cy<1.0f)cy=1.0f;
  6633.     if (cy>126.0f)cy=126.0f;
  6634.  
  6635.     return cy;
  6636. }
  6637.  
  6638. float filterRingMod(char ch,float input,float f,float q)
  6639. {
  6640.   q++;
  6641.   f=float(f*0.0078125f);
  6642.   buf0[ch]+=f*(q*0.125f);
  6643.   if (buf0[ch]>=360.0f)buf0[ch]-=360.0f;
  6644.   return input*SIN[f2i(buf0[ch])];
  6645. }
  6646.  
  6647. float filterRingModStereo(char ch,float input)
  6648. {
  6649.   return float(input*cos(buf0[ch]*0.0174532));
  6650. }
  6651.  
  6652. float filterWater(char ch,float input,float f,float q)
  6653. {
  6654.   f=127.0f-f;
  6655.   float ad=input-buf0[ch];
  6656.   if (ad>1.0f || ad<-1.0f)
  6657.       buf0[ch]+=ad/f;
  6658.  
  6659.   return buf0[ch];
  6660. }
  6661.  
  6662. float filterWaterStereo(char ch,float input,float f,float q)
  6663. {
  6664.   f=127.0f-f;
  6665.   float ad=input-buf1[ch];
  6666.   if (ad>1.0f || ad<-1.0f)
  6667.       buf1[ch]+=ad/f;
  6668.   return buf1[ch];
  6669. }
  6670.  
  6671. float filterDelta(char ch,float input,float f,float q)
  6672. {
  6673.   f=127.0f-f;
  6674.   q*=0.007874f;
  6675.   
  6676.   float output=buf1[ch];
  6677.   if (buf1[ch]>1.0f || buf1[ch]<-1.0f)buf1[ch]*=q;
  6678.  
  6679.   buf0[ch]++;
  6680.   if(buf0[ch]>=f)
  6681.   {
  6682.   buf0[ch]=0;
  6683.   output=input;
  6684.   buf1[ch]=input;
  6685.   }
  6686.   return output;
  6687. }
  6688.  
  6689. float filterDeltaStereo(char ch,float input,float f,float q)
  6690. {
  6691.   f=127.0f-f;
  6692.   q*=0.007874f;
  6693.   
  6694.   float output=buf124[ch];
  6695.   if (buf124[ch]>1.0f || buf124[ch]<-1.0f)buf124[ch]*=q;
  6696.  
  6697.   buf024[ch]++;
  6698.   if(buf024[ch]>=f)
  6699.   {
  6700.   buf024[ch]=0;
  6701.   output=input;
  6702.   buf124[ch]=input;
  6703.   }
  6704.   return output;
  6705. }
  6706.  
  6707. float filterBellShaped(char ch,float input,float f,float q,float g)
  6708. {
  6709.   input++;
  6710.   q*=0.007874f;
  6711.   
  6712.   if (q<0.01f)q=0.01f;
  6713.   float freq=320+(f*127.65625f);
  6714.   float a,b,c;
  6715.   float a0, a1, a2, b1, b2; //filter coefficients
  6716.   float Wn,Wp;
  6717.   float gain=g/6.6f;
  6718.   if (freq > 22100) freq = 22100.0f; // apply Nyquist frequency
  6719.   Wn=1.0f/(6.2831853f*freq); // freq of center
  6720.   Wp=float(Wn/tan(Wn/88200.0f)); // prewarped frequency
  6721.   a=(Wn*Wn*Wp*Wp);
  6722.   float t1=Wn*Wp*q;
  6723.   b=(3+gain)*t1;
  6724.   c=(3-gain)*t1;
  6725.   t1=a+c+1;
  6726.   b2 = (1-c+a)/t1;
  6727.   a2 = (1-b+a)/t1;
  6728.   b1 = a1 = 2*(1-a)/t1;
  6729.   a0 = (a+b+1)/t1;
  6730.   xi0[ch] = input - b1*xi1[ch] - b2*xi2[ch];
  6731.   float output = a0*xi0[ch] + a1*xi1[ch] + a2*xi2[ch];
  6732.   xi2[ch]=xi1[ch];
  6733.   xi1[ch]=xi0[ch];
  6734.   return output;
  6735. }
  6736.  
  6737. void ResetFilters(char tr)
  6738. {buf024[tr]=0.0f;
  6739. buf124[tr]=0.0f;
  6740. buf0[tr]=0.0f;
  6741. buf1[tr]=0.0f;
  6742. fx1[tr]=0.0f;
  6743. fx2[tr]=0.0f;
  6744. fy1[tr]=0.0f;
  6745. fy2[tr]=0.0f;
  6746. xi0[tr]=xi1[tr]=xi2[tr]=0.0f;
  6747. }
  6748.  
  6749. void SeqFill(int st,int en,bool n)
  6750. {
  6751. for(int cl=st;cl<en;cl++)
  6752. for(char trk=0;trk<Songtracks;trk++)
  6753. SACTIVE[cl][trk]=n;
  6754. }        
  6755.  
  6756. void Afloop(void)
  6757. {
  6758. if(actuloop==1 || actuloop==3)
  6759. {for (int a=0;a<200;a++){
  6760.     long ose=a+LoopStart[ped_patsam][ped_split];
  6761.     if (ose<SampleNumSamples[ped_patsam][ped_split]){
  6762.     int v=*(RawSamples[ped_patsam][0][ped_split]+ose)/1024;
  6763.     S->drawVLine(a+220,432,400-v,0x5424);
  6764.     S->drawVLine(a+220,400-v,368,0);
  6765.     }
  6766.     else
  6767.     S->drawVLine(a+20,368,432,0x0121);
  6768. }}
  6769.  
  6770. if(actuloop==2 || actuloop==3)
  6771. {for (int b=0;b<200;b++){
  6772.     long ose=(LoopEnd[ped_patsam][ped_split]-200)+b;
  6773.     if (ose>-1 && ose<SampleNumSamples[ped_patsam][ped_split])
  6774.     {
  6775.     int v=*(RawSamples[ped_patsam][0][ped_split]+ose)/1024;
  6776.     S->drawVLine(b+20,432,400-v,0x6523);
  6777.     S->drawVLine(b+20,400-v,368,0x0001);
  6778.     }
  6779.     else
  6780.     S->drawVLine(b+20,368,432,0x0121);
  6781. }}
  6782. actuloop=0;
  6783. }
  6784.  
  6785. float int_filter2p(char ch,float input,float f,float q, float q2)
  6786. {
  6787. q*=0.0787401f;
  6788. input=filter2px(ch,input,f,q2);
  6789. return float(32767.0f*pow(abs(f2i(input))/32767.0f,1.0f-q/11.0f));
  6790. }
  6791.  
  6792. float filter2px(char ch,float input,float f,float q)
  6793. {
  6794.   f*=0.0078125f;
  6795.   float fa = float(1.0 - f); 
  6796.   float fb = float(q * (1.0 + (1.0/fa)));
  6797.   buf0[ch] = fa * buf0[ch] + f * (input + fb * (buf0[ch] - buf1[ch])); 
  6798.   buf1[ch] = fa * buf1[ch] + f * buf0[ch];
  6799.   float output = buf1[ch];  
  6800.   return output;
  6801. }
  6802.  
  6803. void SaveInst(void)
  6804. {
  6805. guiDial(172,350,80,16,"Save Inst",100);
  6806. FILE *in;
  6807. char Temph[96];
  6808. char extension[10];
  6809. sprintf(extension,"TWNNINS0");
  6810. sprintf (Temph,"Saving '%s.nti' instrument on current directory...",nameins[ped_patsam]);
  6811. mess_box(Temph);
  6812. sprintf(Temph,"%s.nti",nameins[ped_patsam]);
  6813. in = fopen(Temph,"wb");
  6814. if (in!=NULL)
  6815. {
  6816. // Writing NoiseTrekker header & name...
  6817. fwrite(extension, sizeof( char),9,in);
  6818. fwrite(&nameins[ped_patsam], sizeof( char ), 20,in);
  6819.  
  6820. // Writing sample data
  6821. int swrite=ped_patsam;
  6822. fwrite(&Midiprg[swrite],sizeof(char),1,in);
  6823. fwrite(&Synthprg[swrite],sizeof(bool),1,in);
  6824. fwrite(&PARASynth[swrite], sizeof(SynthParameters),1,in);
  6825.  
  6826. for (int slwrite=0;slwrite<16;slwrite++)
  6827. {
  6828. fwrite(&SampleType[swrite][slwrite], sizeof(char ),1,in);
  6829. if (SampleType[swrite][slwrite]!=0)
  6830. {
  6831. fwrite(&SampleName[swrite][slwrite], sizeof(char),256,in);
  6832. fwrite(&Basenote[swrite][slwrite],sizeof(char),1,in);
  6833. fwrite(&LoopStart[swrite][slwrite], sizeof(long ),1,in);
  6834. fwrite(&LoopEnd[swrite][slwrite], sizeof(long ),1,in);
  6835. fwrite(&LoopType[swrite][slwrite], sizeof(char ),1,in);
  6836. fwrite(&SampleNumSamples[swrite][slwrite], sizeof(long ),1,in);
  6837. fwrite(&Finetune[swrite][slwrite], sizeof(char ),1,in);
  6838. fwrite(&SampleVol[swrite][slwrite], sizeof(float ),1,in);
  6839. fwrite(&FDecay[swrite][slwrite], sizeof(float ),1,in);
  6840. fwrite(RawSamples[swrite][0][slwrite], sizeof(short),SampleNumSamples[swrite][slwrite],in);
  6841. fwrite(&SampleChannels[swrite][slwrite], sizeof(char ),1,in);
  6842. if (SampleChannels[swrite][slwrite]==2)
  6843. fwrite(RawSamples[swrite][1][slwrite], sizeof(short),SampleNumSamples[swrite][slwrite],in);
  6844. }// Exist Sample
  6845. }
  6846. fclose(in);
  6847.  
  6848. Read_SMPT();
  6849. last_index=-1;
  6850. ltActualize(0);
  6851. Actualize_Patterned();
  6852. mess_box("Instrument saved succesful...");    
  6853. }
  6854. else
  6855. {
  6856. mess_box("Instrument save failed...");
  6857. }
  6858. if (snamesel==1 || snamesel==4 || snamesel==5){snamesel=0;Actualize_Main_Ed();}
  6859. guiDial(172,350,80,16,"Save Inst",200);
  6860. }
  6861.  
  6862. void LoadInst(void)
  6863. {
  6864. mess_box("Attempting to load a noisetrekker instrument file...");
  6865. Sleep(1000);    
  6866. FILE *in;
  6867. in = fopen(name,"rb");
  6868.  
  6869. if (in!=NULL)
  6870. {
  6871. // Reading and checking extension...
  6872. char extension[10];
  6873. fread(extension, sizeof( char),9,in);
  6874. if (strcmp(extension,"TWNNINS0")==0)
  6875. { /* Ok, extension matched! */
  6876. KillInst();
  6877. mess_box("Loading 'NoiseTrekker' Instrument -> Header");    
  6878. fread(&nameins[ped_patsam], sizeof( char ), 20,in);
  6879.  
  6880. // Reading sample data
  6881. mess_box("Loading 'NoiseTrekker' Instrument -> Sample data");    
  6882.  
  6883. int swrite=ped_patsam;
  6884.  
  6885. fread(&Midiprg[swrite],sizeof(char),1,in);
  6886. fread(&Synthprg[swrite],sizeof(bool),1,in);
  6887. fread(&PARASynth[swrite], sizeof(SynthParameters),1,in);
  6888.  
  6889. for (int slwrite=0;slwrite<16;slwrite++)
  6890. {
  6891. fread(&SampleType[swrite][slwrite], sizeof(char ),1,in);
  6892. if (SampleType[swrite][slwrite]!=0)
  6893. {
  6894. fread(&SampleName[swrite][slwrite], sizeof(char),256,in);
  6895. fread(&Basenote[swrite][slwrite],sizeof(char),1,in);
  6896. fread(&LoopStart[swrite][slwrite], sizeof(long ),1,in);
  6897. fread(&LoopEnd[swrite][slwrite], sizeof(long ),1,in);
  6898. fread(&LoopType[swrite][slwrite], sizeof(char ),1,in);
  6899. fread(&SampleNumSamples[swrite][slwrite], sizeof(long ),1,in);
  6900. fread(&Finetune[swrite][slwrite], sizeof(char ),1,in);
  6901. fread(&SampleVol[swrite][slwrite], sizeof(float ),1,in);
  6902. fread(&FDecay[swrite][slwrite], sizeof(float ),1,in);
  6903. RawSamples[swrite][0][slwrite]=(short *)malloc(SampleNumSamples[swrite][slwrite]*2);
  6904. fread(RawSamples[swrite][0][slwrite], sizeof(short),SampleNumSamples[swrite][slwrite],in);
  6905. fread(&SampleChannels[swrite][slwrite], sizeof(char ),1,in);
  6906. if (SampleChannels[swrite][slwrite]==2)
  6907. {
  6908. RawSamples[swrite][1][slwrite]=(short *)malloc(SampleNumSamples[swrite][slwrite]*2);
  6909. fread(RawSamples[swrite][1][slwrite], sizeof(short),SampleNumSamples[swrite][slwrite],in);
  6910. }
  6911. }// Exist Sample
  6912. }
  6913. fclose(in);
  6914. Actualize_Patterned();
  6915. Actualize_Sample_Ed(2,0);
  6916. mess_box("Instrument loaded ok.");
  6917. }
  6918. else
  6919. {
  6920. mess_box("That file is not a NoiseTrekker instrument-file...");
  6921. }
  6922. }
  6923. else
  6924. {
  6925. mess_box("Instrument loading failed. (Probably: file not found)");
  6926. }
  6927. if (snamesel==1 || snamesel==4 || snamesel==5){snamesel=0;Actualize_Main_Ed();}
  6928. }
  6929.  
  6930. void Coolwrite(int x, int y, int colour, char* txt)
  6931. {
  6932. S->printXY(x-1,y+1,0x00000000,txt);
  6933. S->printXY(x,y,colour,txt);
  6934. }
  6935.  
  6936. void KillInst()
  6937. {
  6938. for(int z=0;z<16;z++)
  6939. {
  6940.     if(SampleType[ped_patsam][z]!=0)
  6941.     {
  6942.     free(RawSamples[ped_patsam][0][z]);
  6943.     
  6944.     if(SampleChannels[ped_patsam][z]==2)
  6945.     free(RawSamples[ped_patsam][1][z]);
  6946.     
  6947.     SampleChannels[ped_patsam][z]=0;
  6948.     SampleType[ped_patsam][z]=0;
  6949.     LoopStart[ped_patsam][z]=0;
  6950.     LoopEnd[ped_patsam][z]=0;
  6951.     LoopType[ped_patsam][z]=0;
  6952.     SampleNumSamples[ped_patsam][z]=0;
  6953.     Finetune[ped_patsam][z]=0;
  6954.     SampleVol[ped_patsam][z]=0.0;
  6955.     FDecay[ped_patsam][z]=0.0;
  6956.     Basenote[ped_patsam][z]=48;
  6957.     sprintf(SampleName[ped_patsam][z],"Unnamed");
  6958.     Midiprg[ped_patsam]=-1;
  6959.     Synthprg[ped_patsam]=false;
  6960.     
  6961.     }    
  6962. }
  6963.  
  6964. }
  6965.  
  6966. void StopIfSp(void)
  6967. {
  6968. for(char u=0;u<MAX_TRACKS;u++)
  6969.  
  6970. if(sp_channelsample[u]==ped_patsam)
  6971. {
  6972. sp_Stage[u]=0;
  6973. Player_FD[u]=0;
  6974. ramper[u]=0;
  6975. }
  6976. }
  6977.  
  6978. void DeleteInstrument(void)
  6979. {
  6980. ss->stop();
  6981. guiDial(320,134,64,16,"Delete",100);
  6982. StopIfSp();
  6983. Sleep(256);
  6984. KillInst();
  6985. mess_box("Instrument deleted.");
  6986. guiDial(320,134,64,16,"Delete",200);
  6987. RefreshSample();
  6988. NewWavy();
  6989. ss->play();
  6990. }
  6991.  
  6992. void RefreshSample(void)
  6993. {
  6994. seditor=0;
  6995. ped_split=0;
  6996. if(userscreen==2){draw_sampleed();Actualize_Sample_Ed(2,0);}
  6997. }
  6998.  
  6999. void FadeToBlack(void)
  7000. {
  7001.     for (float fad=1.0f;fad>0;fad-=0.005f)
  7002.     {S->setGammaFade(fad,fad,fad);Sleep(1);}
  7003. }
  7004.  
  7005. void ShowInfo(void)
  7006. {
  7007. char tmp[256];
  7008. int pattsize=nPatterns*12288;
  7009. int sampsize=0;
  7010.  
  7011. for(int pp=0;pp<256;pp++)
  7012. {
  7013. for(int z=0;z<16;z++)
  7014. {
  7015.     if(SampleType[pp][z]!=0)
  7016.     sampsize+=SampleChannels[pp][z]*SampleNumSamples[pp][z];    
  7017. }
  7018. }
  7019. sprintf(tmp,"Sample bank size: %d bytes, pattern bank [%d patterns]: %d bytes.",sampsize,nPatterns,pattsize);
  7020. mess_box(tmp);
  7021. }
  7022.  
  7023. void draw_exted(void)
  7024. {
  7025. S->setColor(0,0,0);
  7026. bjbox(0,186,CONSOLE_WIDTH,248);
  7027. snamesel=0;
  7028. guiDial(640,433,64,16,"Back",200);
  7029. guiDial3(0,433,638,16,"Extended Pattern Editor Mode",200);        
  7030. if(restx>0)guiDial3(706,433,restx-2,16,"",200);
  7031. VIEWLINE=14;
  7032. VIEWLINE2=-13;
  7033. YVIEW=300;
  7034. Actupated(0);
  7035. }
  7036.  
  7037. void draw_back(void)
  7038. {
  7039. VIEWLINE=7;
  7040. VIEWLINE2=-6;
  7041. YVIEW=244; 
  7042. guiDial3(0,309,110,16,"User Window",200);
  7043. guiDial3(0,327,fsize,122,"",144);
  7044. actlogo=true;
  7045. userscreen=0;draw_mained();Actualize_Main_Ed();
  7046. if(restx>0)guiDial3(772,309,restx-2,16,"",200);
  7047. S->copy(FRAMEWORK, 0, 184);
  7048. Actupated(0);
  7049. }
  7050.  
  7051. void Anat(int posil)
  7052. {
  7053. if(pSequence[posil]>=nPatterns)
  7054. nPatterns=pSequence[posil]+1;
  7055. }
  7056.  
  7057.  
  7058. #include "CSynth_gui_pro.cpp"
  7059. #include "mod_import.cpp"
  7060. int postAction(Console* C)
  7061. {    
  7062.  
  7063. ss->release();
  7064. delete sw;
  7065. FreeAll();
  7066. SelectObject(dc,old_f);DeleteObject(fnt);
  7067. RELEASEINT(MOUSEBACK);
  7068. RELEASEINT(NTKLOGO);
  7069. RELEASEINT(SKIN303);
  7070. RELEASEINT(KNOB1);
  7071. RELEASEINT(PFONT);
  7072. RELEASEINT(FRAMEWORK);
  7073.  
  7074. // Freeing Allocated Patterns
  7075. free(RawPatterns);
  7076. SaveSettings();
  7077. return 0;
  7078. }
  7079.  
  7080. void ComputeStereo(char channel)
  7081. {
  7082. LVol[channel]=1.0f-TPan[channel];
  7083. RVol[channel]=1.0f-LVol[channel];
  7084. if(LVol[channel]>0.5f)LVol[channel]=0.5f;
  7085. if(RVol[channel]>0.5f)RVol[channel]=0.5f;
  7086. }
  7087.